本文整理汇总了PHP中SpamModel::isSpam方法的典型用法代码示例。如果您正苦于以下问题:PHP SpamModel::isSpam方法的具体用法?PHP SpamModel::isSpam怎么用?PHP SpamModel::isSpam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpamModel
的用法示例。
在下文中一共展示了SpamModel::isSpam方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Inserts or updates the discussion via form values.
*
* Events: BeforeSaveDiscussion, AfterSaveDiscussion.
*
* @since 2.0.0
* @access public
*
* @param array $FormPostValues Data sent from the form model.
* @param array $Settings Currently unused.
* @return int $DiscussionID Unique ID of the discussion.
*/
public function save($FormPostValues, $Settings = false)
{
$Session = Gdn::session();
// Define the primary key in this model's table.
$this->defineSchema();
// Add & apply any extra validation rules:
$this->Validation->applyRule('Body', 'Required');
$this->Validation->addRule('MeAction', 'function:ValidateMeAction');
$this->Validation->applyRule('Body', 'MeAction');
$MaxCommentLength = Gdn::config('Vanilla.Comment.MaxLength');
if (is_numeric($MaxCommentLength) && $MaxCommentLength > 0) {
$this->Validation->SetSchemaProperty('Body', 'Length', $MaxCommentLength);
$this->Validation->applyRule('Body', 'Length');
}
// Validate category permissions.
$CategoryID = val('CategoryID', $FormPostValues);
if ($CategoryID > 0) {
$Category = CategoryModel::categories($CategoryID);
if ($Category && !$Session->checkPermission('Vanilla.Discussions.Add', true, 'Category', val('PermissionCategoryID', $Category))) {
$this->Validation->addValidationResult('CategoryID', 'You do not have permission to post in this category');
}
}
// Get the DiscussionID from the form so we know if we are inserting or updating.
$DiscussionID = val('DiscussionID', $FormPostValues, '');
// See if there is a source ID.
if (val('SourceID', $FormPostValues)) {
$DiscussionID = $this->SQL->getWhere('Discussion', arrayTranslate($FormPostValues, array('Source', 'SourceID')))->value('DiscussionID');
if ($DiscussionID) {
$FormPostValues['DiscussionID'] = $DiscussionID;
}
} elseif (val('ForeignID', $FormPostValues)) {
$DiscussionID = $this->SQL->getWhere('Discussion', array('ForeignID' => $FormPostValues['ForeignID']))->value('DiscussionID');
if ($DiscussionID) {
$FormPostValues['DiscussionID'] = $DiscussionID;
}
}
$Insert = $DiscussionID == '' ? true : false;
$this->EventArguments['Insert'] = $Insert;
if ($Insert) {
unset($FormPostValues['DiscussionID']);
// If no categoryid is defined, grab the first available.
if (!val('CategoryID', $FormPostValues) && !c('Vanilla.Categories.Use')) {
$FormPostValues['CategoryID'] = val('CategoryID', CategoryModel::defaultCategory(), -1);
}
$this->addInsertFields($FormPostValues);
// The UpdateUserID used to be required. Just add it if it still is.
if (!$this->Schema->getProperty('UpdateUserID', 'AllowNull', true)) {
$FormPostValues['UpdateUserID'] = $FormPostValues['InsertUserID'];
}
// $FormPostValues['LastCommentUserID'] = $Session->UserID;
$FormPostValues['DateLastComment'] = $FormPostValues['DateInserted'];
} else {
// Add the update fields.
$this->addUpdateFields($FormPostValues);
}
// Set checkbox values to zero if they were unchecked
if (val('Announce', $FormPostValues, '') === false) {
$FormPostValues['Announce'] = 0;
}
if (val('Closed', $FormPostValues, '') === false) {
$FormPostValues['Closed'] = 0;
}
if (val('Sink', $FormPostValues, '') === false) {
$FormPostValues['Sink'] = 0;
}
// Prep and fire event
$this->EventArguments['FormPostValues'] =& $FormPostValues;
$this->EventArguments['DiscussionID'] = $DiscussionID;
$this->fireEvent('BeforeSaveDiscussion');
// Validate the form posted values
$this->validate($FormPostValues, $Insert);
$ValidationResults = $this->validationResults();
// If the body is not required, remove it's validation errors.
$BodyRequired = c('Vanilla.DiscussionBody.Required', true);
if (!$BodyRequired && array_key_exists('Body', $ValidationResults)) {
unset($ValidationResults['Body']);
}
if (count($ValidationResults) == 0) {
// If the post is new and it validates, make sure the user isn't spamming
if (!$Insert || !$this->checkForSpam('Discussion')) {
// Get all fields on the form that relate to the schema
$Fields = $this->Validation->schemaValidationFields();
// Check for spam.
$spam = SpamModel::isSpam('Discussion', $Fields);
if ($spam) {
return SPAM;
}
// Get DiscussionID if one was sent
//.........这里部分代码省略.........
示例2: validateSpamRegistration
/**
*
*
* @param array $User
* @return bool|string
* @since 2.1
*/
public function validateSpamRegistration($User)
{
$DiscoveryText = val('DiscoveryText', $User);
$Log = validateRequired($DiscoveryText);
$Spam = SpamModel::isSpam('Registration', $User, ['Log' => $Log]);
if ($Spam) {
if ($Log) {
// The user entered discovery text.
return self::REDIRECT_APPROVE;
} else {
$this->Validation->addValidationResult('DiscoveryText', 'Tell us why you want to join!');
return false;
}
}
return true;
}
示例3: save
/**
* Insert or update core data about the comment.
*
* Events: BeforeSaveComment, AfterValidateComment, AfterSaveComment.
*
* @param array $FormPostValues Data from the form model.
* @param array $Settings Currently unused.
* @return int $CommentID
* @since 2.0.0
*/
public function save($FormPostValues, $Settings = false)
{
$Session = Gdn::session();
// Define the primary key in this model's table.
$this->defineSchema();
// Add & apply any extra validation rules:
$this->Validation->applyRule('Body', 'Required');
$this->Validation->addRule('MeAction', 'function:ValidateMeAction');
$this->Validation->applyRule('Body', 'MeAction');
$MaxCommentLength = Gdn::config('Vanilla.Comment.MaxLength');
if (is_numeric($MaxCommentLength) && $MaxCommentLength > 0) {
$this->Validation->SetSchemaProperty('Body', 'Length', $MaxCommentLength);
$this->Validation->applyRule('Body', 'Length');
}
$MinCommentLength = c('Vanilla.Comment.MinLength');
if ($MinCommentLength && is_numeric($MinCommentLength)) {
$this->Validation->SetSchemaProperty('Body', 'MinLength', $MinCommentLength);
$this->Validation->addRule('MinTextLength', 'function:ValidateMinTextLength');
$this->Validation->applyRule('Body', 'MinTextLength');
}
// Validate $CommentID and whether this is an insert
$CommentID = val('CommentID', $FormPostValues);
$CommentID = is_numeric($CommentID) && $CommentID > 0 ? $CommentID : false;
$Insert = $CommentID === false;
if ($Insert) {
$this->AddInsertFields($FormPostValues);
} else {
$this->AddUpdateFields($FormPostValues);
}
// Prep and fire event
$this->EventArguments['FormPostValues'] =& $FormPostValues;
$this->EventArguments['CommentID'] = $CommentID;
$this->fireEvent('BeforeSaveComment');
// Validate the form posted values
if ($this->validate($FormPostValues, $Insert)) {
// If the post is new and it validates, check for spam
if (!$Insert || !$this->CheckForSpam('Comment')) {
$Fields = $this->Validation->SchemaValidationFields();
unset($Fields[$this->PrimaryKey]);
$CommentData = $CommentID ? array_merge($Fields, ['CommentID' => $CommentID]) : $Fields;
// Check for spam
$spam = SpamModel::isSpam('Comment', $CommentData);
if ($spam) {
return SPAM;
}
$isValid = true;
$invalidReturnType = false;
$this->EventArguments['CommentData'] = $CommentData;
$this->EventArguments['IsValid'] =& $isValid;
$this->EventArguments['InvalidReturnType'] =& $invalidReturnType;
$this->fireEvent('AfterValidateComment');
if (!$isValid) {
return $invalidReturnType;
}
if ($Insert === false) {
// Log the save.
LogModel::LogChange('Edit', 'Comment', array_merge($Fields, array('CommentID' => $CommentID)));
// Save the new value.
$this->SerializeRow($Fields);
$this->SQL->put($this->Name, $Fields, array('CommentID' => $CommentID));
} else {
// Make sure that the comments get formatted in the method defined by Garden.
if (!val('Format', $Fields) || c('Garden.ForceInputFormatter')) {
$Fields['Format'] = Gdn::config('Garden.InputFormatter', '');
}
// Check for approval
$ApprovalRequired = CheckRestriction('Vanilla.Approval.Require');
if ($ApprovalRequired && !val('Verified', Gdn::session()->User)) {
$DiscussionModel = new DiscussionModel();
$Discussion = $DiscussionModel->getID(val('DiscussionID', $Fields));
$Fields['CategoryID'] = val('CategoryID', $Discussion);
LogModel::insert('Pending', 'Comment', $Fields);
return UNAPPROVED;
}
// Create comment.
$this->SerializeRow($Fields);
$CommentID = $this->SQL->insert($this->Name, $Fields);
}
if ($CommentID) {
$this->EventArguments['CommentID'] = $CommentID;
$this->EventArguments['Insert'] = $Insert;
// IsNewDiscussion is passed when the first comment for new discussions are created.
$this->EventArguments['IsNewDiscussion'] = val('IsNewDiscussion', $FormPostValues);
$this->fireEvent('AfterSaveComment');
}
}
}
// Update discussion's comment count
$DiscussionID = val('DiscussionID', $FormPostValues);
$this->UpdateCommentCount($DiscussionID, array('Slave' => false));
//.........这里部分代码省略.........
示例4: save
//.........这里部分代码省略.........
// index hint
$CheckActivity = $this->SQL->getWhere('Activity', $Where)->firstRow();
if ($CheckActivity) {
return false;
}
}
// Check to share the activity.
if (val('Share', $Options)) {
$this->Share($Activity);
}
// Group he activity.
if ($GroupBy = val('GroupBy', $Options)) {
$GroupBy = (array) $GroupBy;
$Where = array();
foreach ($GroupBy as $ColumnName) {
$Where[$ColumnName] = $Activity[$ColumnName];
}
$Where['NotifyUserID'] = $Activity['NotifyUserID'];
// Make sure to only group activities by day.
$Where['DateInserted >'] = Gdn_Format::toDateTime(strtotime('-1 day'));
// See if there is another activity to group these into.
$GroupActivity = $this->SQL->getWhere('Activity', $Where)->firstRow(DATASET_TYPE_ARRAY);
if ($GroupActivity) {
$GroupActivity['Data'] = @unserialize($GroupActivity['Data']);
$Activity = $this->mergeActivities($GroupActivity, $Activity);
$NotificationInc = 0;
}
}
$Delete = false;
if ($Activity['Emailed'] == self::SENT_PENDING) {
$this->email($Activity);
$Delete = val('_Delete', $Activity);
}
$ActivityData = $Activity['Data'];
if (isset($Activity['Data']) && is_array($Activity['Data'])) {
$Activity['Data'] = serialize($Activity['Data']);
}
$this->defineSchema();
$Activity = $this->filterSchema($Activity);
$ActivityID = val('ActivityID', $Activity);
if (!$ActivityID) {
if (!$Delete) {
$this->addInsertFields($Activity);
touchValue('DateUpdated', $Activity, $Activity['DateInserted']);
$this->EventArguments['Activity'] =& $Activity;
$this->EventArguments['ActivityID'] = null;
$Handled = false;
$this->EventArguments['Handled'] =& $Handled;
$this->fireEvent('BeforeSave');
if (count($this->validationResults()) > 0) {
return false;
}
if ($Handled) {
// A plugin handled this activity so don't save it.
return $Activity;
}
if (val('CheckSpam', $Options)) {
// Check for spam
$Spam = SpamModel::isSpam('Activity', $Activity);
if ($Spam) {
return SPAM;
}
// Check for approval
$ApprovalRequired = CheckRestriction('Vanilla.Approval.Require');
if ($ApprovalRequired && !val('Verified', Gdn::session()->User)) {
LogModel::insert('Pending', 'Activity', $Activity);
return UNAPPROVED;
}
}
$ActivityID = $this->SQL->insert('Activity', $Activity);
$Activity['ActivityID'] = $ActivityID;
}
} else {
$Activity['DateUpdated'] = Gdn_Format::toDateTime();
unset($Activity['ActivityID']);
$this->EventArguments['Activity'] =& $Activity;
$this->EventArguments['ActivityID'] = $ActivityID;
$this->fireEvent('BeforeSave');
if (count($this->validationResults()) > 0) {
return false;
}
$this->SQL->put('Activity', $Activity, array('ActivityID' => $ActivityID));
$Activity['ActivityID'] = $ActivityID;
}
$Activity['Data'] = $ActivityData;
if (isset($CommentActivity)) {
$CommentActivity['Data']['SharedActivityID'] = $Activity['ActivityID'];
$CommentActivity['Data']['SharedNotifyUserID'] = $Activity['NotifyUserID'];
$this->setField($CommentActivity['ActivityID'], 'Data', $CommentActivity['Data']);
}
if ($NotificationInc > 0) {
$CountNotifications = Gdn::userModel()->getID($Activity['NotifyUserID'])->CountNotifications + $NotificationInc;
Gdn::userModel()->setField($Activity['NotifyUserID'], 'CountNotifications', $CountNotifications);
}
// If this is a wall post then we need to notify on that.
if (val('Name', $ActivityType) == 'WallPost' && $Activity['NotifyUserID'] == self::NOTIFY_PUBLIC) {
$this->notifyWallPost($Activity);
}
return $Activity;
}