function getFormField()
 {
     if ($protector = SpamProtectorManager::get_spam_protector()) {
         if ($protector) {
             $protector = new $protector();
             return $protector->getFormField($this->Name, $this->Title, null);
         }
     }
     return false;
 }
 function getRecaptchaField()
 {
     $field = null;
     $spamProtector = SpamProtectorManager::get_spam_protector();
     if ($spamProtector == "RecaptchaProtector") {
         $field = new RecaptchaField("Recaptcha", "Please enter text");
         $field->jsOptions = array('theme' => 'clean');
         $field->addExtraClass("required");
     }
     return $field;
 }
 function JobRegistrationRequestForm()
 {
     $data = Session::get("FormInfo.Form_JobRegistrationRequestForm.data");
     $form = new JobRegistrationRequestForm($this, 'JobRegistrationRequestForm');
     // we should also load the data stored in the session. if failed
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Optional spam protection
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form);
     }
     return $form;
 }
 function JobForm()
 {
     $data = Session::get("FormInfo.Form_JobForm.data");
     Requirements::css('jobs/css/job.registration.form.css');
     Requirements::javascript("jobs/js/job.registration.form.js");
     $form = new JobForm($this, 'JobForm');
     // we should also load the data stored in the session. if failed
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Optional spam protection
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form);
     }
     return $form;
 }
 public function EventForm()
 {
     $this->commonScripts();
     Requirements::css('events/css/event.registration.form.css');
     Requirements::javascript("events/js/event.registration.form.js");
     $data = Session::get("FormInfo.Form_EventForm.data");
     $form = new EventForm($this->owner, 'EventForm', false);
     // we should also load the data stored in the session. if failed
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Optional spam protection
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form);
     }
     return $form;
 }
 public function NewsRequestForm()
 {
     $this->commonScripts();
     Requirements::css('news/code/ui/frontend/css/news.form.css');
     Requirements::javascript("news/code/ui/frontend/js/news.form.js");
     $data = Session::get("FormInfo.Form_NewsRequestForm.data");
     $article = null;
     $is_news_manager = Member::currentUser() && Member::currentUser()->isNewsManager();
     if (isset($this->requestParams['articleID']) && $is_news_manager) {
         $article_id = $this->requestParams['articleID'];
         $article = $this->news_repository->getNewsByID($article_id);
     }
     $form = new NewsRequestForm($this, 'NewsRequestForm', $article, $is_news_manager, false);
     // we should also load the data stored in the session. if failed
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Optional spam protection
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form);
     }
     return $form;
 }
 function Form()
 {
     if (isset($_REQUEST["BackURL"])) {
         Session::set('BackURL', $_REQUEST["BackURL"]);
     }
     $member = Member::currentUser();
     $fields = new FieldList();
     $passwordField = null;
     if ($member) {
         $name = $member->getName();
         //if($member && $member->Password != '') {$passwordField->setCanBeEmpty(true);}
         $action = new FormAction("submit", "Update your details");
         $action->addExtraClass("updateButton");
         $actions = new FieldList($action);
     } else {
         $passwordField = new ConfirmedPasswordField("Password", "Password");
         $action = new FormAction("submit", "Register");
         $action->addExtraClass("registerButton");
         $actions = new FieldList($action);
         $member = new Member();
     }
     $memberFormFields = $member->getMemberFormFields();
     if ($memberFormFields) {
         if (is_array(self::$fields_to_remove) && count(self::$fields_to_remove)) {
             foreach (self::$fields_to_remove as $fieldName) {
                 $memberFormFields->removeByName($fieldName);
             }
         }
         $fields->merge($memberFormFields);
     }
     if ($passwordField) {
         $fields->push($passwordField);
     }
     foreach (self::$required_fields as $fieldName) {
         $fields->fieldByName($fieldName)->addExtraClass("RequiredField");
     }
     $requiredFields = new RequiredFields(self::$required_fields);
     $form = new Form($this, "Form", $fields, $actions, $requiredFields);
     // Load any data avaliable into the form.
     if ($member) {
         $member->Password = null;
         $form->loadDataFrom($member);
     }
     $data = Session::get("FormInfo.Form_Form.data");
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Optional spam protection
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form);
     }
     if (!isset($_REQUEST["Password"])) {
         $form->fields()->fieldByName("Password")->SetValue("");
     }
     return $form;
 }
Пример #8
0
 /**
  * Factory method for the registration form
  *
  * @return Form Returns the registration form
  */
 function RegistrationForm()
 {
     $data = Session::get("FormInfo.Form_RegistrationForm.data");
     $use_openid = $this->getForumHolder()->OpenIDAvailable() == true && (isset($data['IdentityURL']) && !empty($data['IdentityURL'])) || isset($_POST['IdentityURL']) && !empty($_POST['IdentityURL']);
     $fields = singleton('Member')->getForumFields($use_openid, true);
     // If a BackURL is provided, make it hidden so the post-registration
     // can direct to it.
     if (isset($_REQUEST['BackURL'])) {
         $fields->push(new HiddenField('BackURL', 'BackURL', $_REQUEST['BackURL']));
     }
     $validator = singleton('Member')->getForumValidator(!$use_openid);
     $form = new Form($this, 'RegistrationForm', $fields, new FieldSet(new FormAction("doregister", _t('ForumMemberProfile.REGISTER', 'Register'))), $validator);
     // Guard against automated spam registrations by optionally adding a field
     // that is supposed to stay blank (and is hidden from most humans).
     // The label and field name are intentionally common ("username"),
     // as most spam bots won't resist filling it out. The actual username field
     // on the forum is called "Nickname".
     if (ForumHolder::$use_honeypot_on_register) {
         $form->Fields()->push(new LiteralField('HoneyPot', '<div style="position: absolute; left: -9999px;">' . '<label for="RegistrationForm_username">' . _t('ForumMemberProfile.LeaveBlank', 'Don\'t enter anything here') . '</label>' . '<input type="text" name="username" id="RegistrationForm_username" value="" />' . '</div>'));
     }
     $member = new Member();
     // we should also load the data stored in the session. if failed
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Optional spam protection
     if (class_exists('SpamProtectorManager') && ForumHolder::$use_spamprotection_on_register) {
         SpamProtectorManager::update_form($form);
     }
     return $form;
 }
Пример #9
0
 /**
  * Mark a post as spam. Deletes any posts or threads created by that user
  * and removes their user account from the site
  *
  * Must be logged in and have the correct permissions to do marking
  */
 function markasspam()
 {
     if ($this->isAdmin() && isset($this->urlParams['ID'])) {
         $post = DataObject::get_by_id('Post', $this->urlParams['ID']);
         if ($post) {
             // send spam feedback if needed
             if (class_exists('SpamProtectorManager')) {
                 SpamProtectorManager::send_feedback($post, 'spam');
             }
             // some posts do not have authors
             if ($author = $post->Author()) {
                 $SQL_id = Convert::raw2sql($author->ID);
                 // delete all threads and posts from that user
                 $posts = DataObject::get('Post', "\"AuthorID\" = '{$SQL_id}'");
                 if ($posts) {
                     foreach ($posts as $post) {
                         if ($post->isFirstPost()) {
                             // post was the start of a thread, Delete the whole thing
                             $post->Thread()->delete();
                         } else {
                             if ($post->ID) {
                                 $post->delete();
                             }
                         }
                     }
                 }
                 // delete the authors account
                 $author->delete();
             } else {
                 $post->delete();
             }
         }
     }
     return Director::is_ajax() ? true : $this->redirect($this->Link());
 }
Пример #10
0
 /**
  * Set the name of the spam protecter class
  * 
  * @param String the name of protecter field class
  */
 public static function set_spam_protector($protector)
 {
     self::$spam_protector = $protector;
 }
 public static function set_spam_protector($protector)
 {
     Deprecation::notice('1.1', 'SpamProtectorManager::set_spam_protector() is deprecated. ' . 'Use the new config system. FormSpamProtectorExtension.default_spam_protector');
     self::$spam_protector = $protector;
 }
 function PostCommentForm()
 {
     if (!$this->page->ProvideComments) {
         return false;
     }
     $fields = new FieldSet(new HiddenField("ParentID", "ParentID", $this->page->ID));
     $member = Member::currentUser();
     if ((self::$comments_require_login || self::$comments_require_permission) && $member && $member->FirstName) {
         // note this was a ReadonlyField - which displayed the name in a span as well as the hidden field but
         // it was not saving correctly. Have changed it to a hidden field. It passes the data correctly but I
         // believe the id of the form field is wrong.
         $fields->push(new ReadonlyField("NameView", _t('PageCommentInterface.YOURNAME', 'Your name'), $member->getName()));
         $fields->push(new HiddenField("Name", "", $member->getName()));
     } else {
         $fields->push(new TextField("Name", _t('PageCommentInterface.YOURNAME', 'Your name')));
     }
     // optional commenter URL
     $fields->push(new TextField("CommenterURL", _t('PageCommentInterface.COMMENTERURL', "Your website URL")));
     if (MathSpamProtection::isEnabled()) {
         $fields->push(new TextField("Math", sprintf(_t('PageCommentInterface.SPAMQUESTION', "Spam protection question: %s"), MathSpamProtection::getMathQuestion())));
     }
     $fields->push(new TextareaField("Comment", _t('PageCommentInterface.YOURCOMMENT', "Comments")));
     $form = new PageCommentInterface_Form($this, "PostCommentForm", $fields, new FieldSet(new FormAction("postcomment", _t('PageCommentInterface.POST', 'Post'))), new RequiredFields('Name', 'Comment'));
     // Set it so the user gets redirected back down to the form upon form fail
     $form->setRedirectToFormOnValidationError(true);
     // Optional Spam Protection.
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form, null, array('Name' => 'author_name', 'CommenterURL' => 'author_url', 'Comment' => 'post_body'));
         self::set_use_ajax_commenting(false);
     }
     // Add note about moderated comments
     if (PageComment::moderationEnabled()) {
         $fields->push(new LiteralField('ModerationNote', sprintf('<p class="moderationMessage"><small>%s</small></p>', _t('PageCommentInterface.ModerationEnabledNote', 'Note: Comments are moderated and won\'t show until they are approved'))));
     }
     // Shall We use AJAX?
     if (self::$use_ajax_commenting) {
         Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js');
         Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js');
         Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/effects.js');
         Requirements::javascript(CMS_DIR . '/javascript/PageCommentInterface.js');
     }
     $this->extend('updatePageCommentForm', $form);
     // Load the users data from a cookie
     $cookie = Cookie::get('PageCommentInterface_Data');
     if ($cookie) {
         $visibleFields = array();
         foreach ($fields as $field) {
             if (!$field instanceof HiddenField) {
                 $visibleFields[] = $field->Name();
             }
         }
         $form->loadDataFrom(Convert::json2array($cookie), false, $visibleFields);
     }
     return $form;
 }
Пример #13
0
 /**
  * Report a Spam Comment as valid comment (not spam)
  */
 function reportham($request)
 {
     // Protect against CSRF on destructive action
     $token = SecurityToken::inst();
     if (!$token->checkRequest($request)) {
         return $this->httpError(400);
     }
     $comment = DataObject::get_by_id("PageComment", $request->param('ID'));
     if ($comment && $comment->canEdit()) {
         // if spam protection module exists
         if (class_exists('SpamProtectorManager')) {
             SpamProtectorManager::send_feedback($comment, 'ham');
         }
         if (SSAkismet::isEnabled()) {
             try {
                 $akismet = new SSAkismet();
                 $akismet->setCommentAuthor($comment->getField('Name'));
                 $akismet->setCommentContent($comment->getField('Comment'));
                 $akismet->submitHam();
             } catch (Exception $e) {
                 // Akismet didn't work, most likely the service is down.
             }
         }
         $comment->setField('IsSpam', false);
         $comment->write();
     }
     if (Director::is_ajax()) {
         echo $comment->renderWith('PageCommentInterface_singlecomment');
     } else {
         Director::redirectBack();
     }
 }
 function JobForm()
 {
     $this->commonScripts();
     Requirements::javascript(Director::protocol() . "maps.googleapis.com/maps/api/js?sensor=false");
     Requirements::javascript("marketplace/code/ui/admin/js/geocoding.jquery.js");
     Requirements::css('jobs/css/job.registration.form.css');
     Requirements::javascript("jobs/js/job.registration.form.js");
     $data = Session::get("FormInfo.Form_JobForm.data");
     $form = new JobForm($this->owner, 'JobForm', false);
     // we should also load the data stored in the session. if failed
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Optional spam protection
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form);
     }
     return $form;
 }
Пример #15
0
 /**
  * Mark a post as spam. Deletes any posts or threads created by that user
  * and removes their user account from the site
  *
  * Must be logged in and have the correct permissions to do marking
  */
 function markasspam()
 {
     $currentUser = Member::currentUser();
     if (!isset($this->urlParams['ID'])) {
         return $this->httpError(400);
     }
     if (!$this->canModerate()) {
         return $this->httpError(403);
     }
     $post = DataObject::get_by_id('Post', $this->urlParams['ID']);
     if ($post) {
         // send spam feedback if needed
         if (class_exists('SpamProtectorManager')) {
             SpamProtectorManager::send_feedback($post, 'spam');
         }
         $postID = $post->ID;
         // post was the start of a thread, Delete the whole thing
         if ($post->isFirstPost()) {
             $post->Thread()->delete();
         }
         // Delete the current post
         $post->delete();
         // Log deletion event
         SS_Log::log(sprintf('Marked post #%d as spam, by moderator %s (#%d)', $postID, $currentUser->Email, $currentUser->ID), SS_Log::NOTICE);
         // Suspend the member (rather than deleting him),
         // which gives him or a moderator the chance to revoke a decision.
         if ($author = $post->Author()) {
             $author->SuspendedUntil = date('Y-m-d', strtotime('+99 years', SS_Datetime::now()->Format('U')));
             $author->write();
         }
         SS_Log::log(sprintf('Suspended member %s (#%d) for spam activity, by moderator %s (#%d)', $author->Email, $author->ID, $currentUser->Email, $currentUser->ID), SS_Log::NOTICE);
     }
     return Director::is_ajax() ? true : $this->redirect($this->Link());
 }
 /**
  * Factory method for the registration form
  *
  * @return Form Returns the registration form
  */
 function RegistrationForm()
 {
     $data = Session::get("FormInfo.Form_RegistrationForm.data");
     $use_openid = $this->getForumHolder()->OpenIDAvailable() == true && (isset($data['IdentityURL']) && !empty($data['IdentityURL'])) || isset($_POST['IdentityURL']) && !empty($_POST['IdentityURL']);
     $fields = singleton('Member')->getForumFields($use_openid, true);
     // If a BackURL is provided, make it hidden so the post-registration
     // can direct to it.
     if (isset($_REQUEST['BackURL'])) {
         $fields->push(new HiddenField('BackURL', 'BackURL', $_REQUEST['BackURL']));
     }
     $validator = singleton('Member')->getForumValidator(!$use_openid);
     $form = new Form($this, 'RegistrationForm', $fields, new FieldSet(new FormAction("doregister", _t('ForumMemberProfile.REGISTER', 'Register'))), $validator);
     $member = new Member();
     // we should also load the data stored in the session. if failed
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Optional spam protection
     if (class_exists('SpamProtectorManager') && ForumHolder::$use_spamprotection_on_register) {
         SpamProtectorManager::update_form($form);
     }
     return $form;
 }
 /**
  * @uses   MemberProfilePage_Controller::getProfileFields
  * @return Form
  */
 public function RegisterForm()
 {
     $form = new Form($this, 'RegisterForm', $this->getProfileFields('Registration'), new FieldList(new FormAction('register', _t('MemberProfiles.REGISTER', 'Register'))), new MemberProfileValidator($this->Fields()));
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form);
     }
     $this->extend('updateRegisterForm', $form);
     return $form;
 }
Пример #18
0
 /**
  * Report a Spam Comment as valid comment (not spam)
  */
 function reportham()
 {
     $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
     if ($comment && $comment->canEdit()) {
         // if spam protection module exists
         if (class_exists('SpamProtectorManager')) {
             SpamProtectorManager::send_feedback($comment, 'ham');
         }
         if (SSAkismet::isEnabled()) {
             try {
                 $akismet = new SSAkismet();
                 $akismet->setCommentAuthor($comment->getField('Name'));
                 $akismet->setCommentContent($comment->getField('Comment'));
                 $akismet->submitHam();
             } catch (Exception $e) {
                 // Akismet didn't work, most likely the service is down.
             }
         }
         $comment->setField('IsSpam', false);
         $comment->write();
     }
     if (Director::is_ajax()) {
         echo $comment->renderWith('PageCommentInterface_singlecomment');
     } else {
         Director::redirectBack();
     }
 }
Пример #19
0
 /**
  * Disable the AJAX commenting and update the form
  * with the {@link SpamProtectorField} which is enabled
  */
 function alterCommentForm(&$form)
 {
     SpamProtectorManager::update_form($form, null, array('Name' => 'author_name', 'CommenterURL' => 'author_url', 'Comment' => 'post_body', 'Email' => 'author_email'));
 }
Пример #20
0
 function PostCommentForm()
 {
     $fields = new FieldSet(new HiddenField("ParentID", "ParentID", $this->page->ID));
     $member = Member::currentUser();
     if ((self::$comments_require_login || self::$comments_require_permission) && $member && $member->FirstName) {
         // note this was a ReadonlyField - which displayed the name in a span as well as the hidden field but
         // it was not saving correctly. Have changed it to a hidden field. It passes the data correctly but I
         // believe the id of the form field is wrong.
         $fields->push(new ReadonlyField("NameView", _t('PageCommentInterface.YOURNAME', 'Your name'), $member->getName()));
         $fields->push(new HiddenField("Name", "", $member->getName()));
     } else {
         $fields->push(new TextField("Name", _t('PageCommentInterface.YOURNAME', 'Your name')));
     }
     // optional commenter URL
     $fields->push(new TextField("CommenterURL", _t('PageCommentInterface.COMMENTERURL', "Your website URL")));
     if (MathSpamProtection::isEnabled()) {
         $fields->push(new TextField("Math", sprintf(_t('PageCommentInterface.SPAMQUESTION', "Spam protection question: %s"), MathSpamProtection::getMathQuestion())));
     }
     $fields->push(new TextareaField("Comment", _t('PageCommentInterface.YOURCOMMENT', "Comments")));
     $form = new PageCommentInterface_Form($this, "PostCommentForm", $fields, new FieldSet(new FormAction("postcomment", _t('PageCommentInterface.POST', 'Post'))));
     // Set it so the user gets redirected back down to the form upon form fail
     $form->setRedirectToFormOnValidationError(true);
     // Optional Spam Protection.
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form, null, array('Name', 'CommenterURL', 'Comment'));
         self::set_use_ajax_commenting(false);
     }
     // Shall We use AJAX?
     if (self::$use_ajax_commenting) {
         Requirements::javascript(THIRDPARTY_DIR . '/behaviour.js');
         Requirements::javascript(THIRDPARTY_DIR . '/prototype.js');
         Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/effects.js');
         Requirements::javascript(CMS_DIR . '/javascript/PageCommentInterface.js');
     }
     // Load the data from Session
     $form->loadDataFrom(array("Name" => Cookie::get("PageCommentInterface_Name"), "Comment" => Cookie::get("PageCommentInterface_Comment"), "CommenterURL" => Cookie::get("PageCommentInterface_CommenterURL")));
     return $form;
 }
 public function MarketPlaceReviewForm()
 {
     Requirements::javascript(Director::protocol() . "ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js");
     Requirements::javascript(Director::protocol() . "ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.min.js");
     Requirements::combine_files('marketplace_review_form.js', array("themes/openstack/javascript/jquery.validate.custom.methods.js", "marketplace/code/ui/frontend/js/star-rating.min.js", "marketplace/code/ui/frontend/js/marketplace.review.js"));
     $css_files = array("marketplace/code/ui/frontend/css/star-rating.min.css", "marketplace/code/ui/frontend/css/marketplace-review.css");
     foreach ($css_files as $css_file) {
         Requirements::css($css_file);
     }
     $form = new MarketPlaceReviewForm($this, 'MarketPlaceReviewForm');
     $data = Session::get("FormInfo.Form_MarketPlaceReviewForm.data");
     $review = $this->review_repository->getReview($this->company_service_ID, Member::CurrentUserID());
     if (is_array($data)) {
         //get data from cache
         $form->loadDataFrom($data);
     } elseif ($review) {
         // get submitted review
         $form->loadDataFrom($review);
     }
     // Optional spam protection
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form);
     }
     return $form;
 }
Пример #22
0
<?php

global $project;
$project = 'mysite';
global $databaseConfig;
$databaseConfig = array("type" => 'MySQLDatabase', "server" => 'localhost', "username" => '', "password" => '', "database" => '', "path" => '');
MySQLDatabase::set_connection_charset('utf8');
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.org/themes/
SSViewer::set_theme('comperio');
// Set the site locale
i18n::set_locale('it_IT');
// enable nested URLs for this site (e.g. page/sub-page/)
SiteTree::enable_nested_urls();
//Enable site search
FulltextSearchable::enable();
// Logging
SS_Log::add_writer(new SS_LogFileWriter(__DIR__ . '/../logs/silverstripe.log'), SS_Log::NOTICE, '<=');
HtmlEditorConfig::get('cms')->setOption('valid_elements', '*[*]');
HtmlEditorConfig::get('cms')->setOption('extended_valid_elements', str_replace('img[', 'img[style|', HtmlEditorConfig::get('cms')->getOption('extended_valid_elements')));
// Recaptcha api keys
RecaptchaField::$public_api_key = '';
RecaptchaField::$private_api_key = '';
//Integrate with spam protector
SpamProtectorManager::set_spam_protector("RecaptchaProtector");
//Add featured image to blog entry
DataObject::add_extension('BlogEntry', 'BlogEntryDecorator');