![]() |
|
sfPropelSpamTagBehaviorPlugin - 0.9.1Spam Tag behavior for Propel. |
|
![]() |
1
user
Sign-in
to change your status |
Spam Tag behavior for Propel. |
| Name | Status | |
|---|---|---|
|
|
lead | moc.tcejorp-ynofmys <<ta>> ottoninaz.siocnarf |
Copyright (c) 2007 Francois Zaninotto
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Version | License | API | Released |
|---|---|---|---|
| 0.9.1beta | MIT license | 0.9.1beta | 09/09/2007 |
| 0.9.0beta | MIT license | 0.9.0beta | 23/03/2007 |
| Version | License | API | Released |
|---|---|---|---|
| 0.9.1beta | MIT license | 0.9.1beta | 09/09/2007 |
| 0.9.0beta | MIT license | 0.9.0beta | 23/03/2007 |
The sfPropelSpamTagBehaviorPlugin is a symfony plugin that provides a new Propel behavior.
If you enable this behavior for one of your model class, all objects of this class with the attribute is_spam set to true will no longer appear on database requests.
etion.
Install the plugin
$ symfony plugin-install http://plugins.symfony-project.com/sfPropelSpamTagBehaviorPlugin
Enable Propel behavior support in propel.ini:
propel.builder.AddBehaviors = true
If you use symfony 1.0, change one builder class in propel.ini to avoid a bug in behaviors (not necessary in sf1.1):
; builder settings propel.builder.peer.class = plugins.sfPropelSpamTagBehaviorPlugin.lib.SfPeerBuilder
Each table for which you want this behavior enabled must have one integer column to support the moderation state. If there is none, add a moderation_status column in schema.yml
propel: item: id: title: varchar(255) body: longvarchar created_at: updated_at: moderation_status: { type: integer, default: 1, index: true } # Add this column to each table
Activate the behavior for those of your Propel models that need spam moderation:
// lib/model/Item.php class Item { }
sfPropelBehavior::add('Item', array('spam_tag'));
By default, the plugin will consider the moderation_status column for this model. You can also specify another column if your model doesn't allow you to use a moderation_status column:
sfPropelBehavior::add('Item', array('spam_tag' => array('column' => 'my_spam_tag')));
Note that the column must still be an integer with default value equal to '1'.
Rebuild your model:
$ symfony propel-build-model
If you enable the behavior on a model, selection methods of this model (retrieveByPk, doCount, doSelect, doSelectOne, doSelectJoinXXX, doSelectJoinAll, doSelectJoinAllExceptXXX, doSelectRS) will not return objects marked as spam.
$item = new Item();
$item->save();
$id = $item->getId();
$item->tagAsSpam();
$item = ItemPeer::retrieveByPk($id); // Returns null
You can inspect the spam tag of any object through the getSpamTag() method.
$spam_tag = $item->getSpamTag();
switch($spam_tag)
{
case sfPropelSpamTagBehavior::TAGGED_SAFE:
echo "The item has been checked and marked as safe";
break;
case sfPropelSpamTagBehavior::NOT_CHECKED:
echo "The item is not yet checked";
break;
case sfPropelSpamTagBehavior::TAGGED_AUTO_SPAM:
echo "The item has been checked by an automated service and marked as spam";
break;
case sfPropelSpamTagBehavior::TAGGED_SPAM:
echo "The item has been checked and marked as spam";
}
By default, records with a NOT_CHECKED and TAGGED_SAFE status are shown, others are hidden. Nevertheless, if you want to force moderation, you just need to change one setting in the app.yml:
all:
sfPropelSpamTagBehavior:
display_treshold: 0 # Only allow records marked TAGGED_SAFE
#display_treshold: 1 # Allow records marked TAGGED_SAFE, and NOT_CHECKED
#display_treshold: 2 # Allow records marked TAGGED_SAFE, NOT_CHECKED, and TAGGED_AUTO_SPAM
#display_treshold: 3 # Allow all records
With this setting, only records marked with TAGGED_SAFE are returned.
The behavior can be deactivated temporarily for all models through the sfPropelSpamTagBehavior::disable() method. This will allow you to query the database for tagged records.
$item = ItemPeer::retrieveByPk($id); // Returns null
sfPropelSpamTagBehavior::disable();
$item = ItemPeer::retrieveByPk($id); // Returns an item
Don't forget to enable the behavior again afterwards:
sfPropelSpamTagBehavior::enable();
