| 1 |
= sfPropelSpamTagBehaviorPlugin plugin = |
|---|
| 2 |
|
|---|
| 3 |
The `sfPropelSpamTagBehaviorPlugin` is a symfony plugin that provides a new Propel behavior related to spam filtering on records. If you enable this behavior for one of your model class, all objects of this class with the attribute `SpamTag` set to more than `1` will no longer appear on database queries. |
|---|
| 4 |
|
|---|
| 5 |
== Installation == |
|---|
| 6 |
|
|---|
| 7 |
* Install the plugin |
|---|
| 8 |
|
|---|
| 9 |
{{{ |
|---|
| 10 |
$ symfony plugin-install http://plugins.symfony-project.com/sfPropelSpamTagBehaviorPlugin |
|---|
| 11 |
}}} |
|---|
| 12 |
|
|---|
| 13 |
* Enable Propel behavior support in `propel.ini`: |
|---|
| 14 |
|
|---|
| 15 |
{{{ |
|---|
| 16 |
propel.builder.AddBehaviors = true |
|---|
| 17 |
}}} |
|---|
| 18 |
|
|---|
| 19 |
* If you use symfony 1.0, change one builder class in `propel.ini` to avoid a bug in behaviors (not necessary in symfony 1.1): |
|---|
| 20 |
|
|---|
| 21 |
{{{ |
|---|
| 22 |
; builder settings |
|---|
| 23 |
propel.builder.peer.class = plugins.sfPropelSpamTagBehaviorPlugin.lib.SfPeerBuilder |
|---|
| 24 |
}}} |
|---|
| 25 |
|
|---|
| 26 |
* 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` |
|---|
| 27 |
|
|---|
| 28 |
{{{ |
|---|
| 29 |
propel: |
|---|
| 30 |
item: |
|---|
| 31 |
id: |
|---|
| 32 |
title: varchar(255) |
|---|
| 33 |
body: longvarchar |
|---|
| 34 |
created_at: |
|---|
| 35 |
updated_at: |
|---|
| 36 |
moderation_status: { type: integer, default: 1, index: true } # Add this column to each table |
|---|
| 37 |
}}} |
|---|
| 38 |
|
|---|
| 39 |
* Activate the behavior for those of your Propel models that need spam moderation: |
|---|
| 40 |
|
|---|
| 41 |
{{{ |
|---|
| 42 |
// lib/model/Item.php |
|---|
| 43 |
class Item |
|---|
| 44 |
{ |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
sfPropelBehavior::add('Item', array('spam_tag')); |
|---|
| 48 |
}}} |
|---|
| 49 |
|
|---|
| 50 |
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: |
|---|
| 51 |
|
|---|
| 52 |
{{{ |
|---|
| 53 |
sfPropelBehavior::add('Item', array('spam_tag' => array('column' => 'my_spam_tag'))); |
|---|
| 54 |
}}} |
|---|
| 55 |
|
|---|
| 56 |
Note that the column must still be an integer with default value equal to '1'. |
|---|
| 57 |
|
|---|
| 58 |
* Rebuild your model: |
|---|
| 59 |
|
|---|
| 60 |
{{{ |
|---|
| 61 |
$ symfony propel-build-model |
|---|
| 62 |
}}} |
|---|
| 63 |
|
|---|
| 64 |
== Usage == |
|---|
| 65 |
|
|---|
| 66 |
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. |
|---|
| 67 |
|
|---|
| 68 |
{{{ |
|---|
| 69 |
$item = new Item(); |
|---|
| 70 |
$item->save(); |
|---|
| 71 |
$id = $item->getId(); |
|---|
| 72 |
$item->tagAsSpam(); |
|---|
| 73 |
$item = ItemPeer::retrieveByPk($id); // Returns null |
|---|
| 74 |
}}} |
|---|
| 75 |
|
|---|
| 76 |
You can inspect the spam tag of any object through the `getSpamTag()` method. |
|---|
| 77 |
|
|---|
| 78 |
{{{ |
|---|
| 79 |
$spam_tag = $item->getSpamTag(); |
|---|
| 80 |
switch($spam_tag) |
|---|
| 81 |
{ |
|---|
| 82 |
case sfPropelSpamTagBehavior::TAGGED_SAFE: |
|---|
| 83 |
echo "The item has been checked and marked as safe"; |
|---|
| 84 |
break; |
|---|
| 85 |
case sfPropelSpamTagBehavior::NOT_CHECKED: |
|---|
| 86 |
echo "The item is not yet checked"; |
|---|
| 87 |
break; |
|---|
| 88 |
case sfPropelSpamTagBehavior::TAGGED_AUTO_SPAM: |
|---|
| 89 |
echo "The item has been checked by an automated service and marked as spam"; |
|---|
| 90 |
break; |
|---|
| 91 |
case sfPropelSpamTagBehavior::TAGGED_SPAM: |
|---|
| 92 |
echo "The item has been checked and marked as spam"; |
|---|
| 93 |
} |
|---|
| 94 |
}}} |
|---|
| 95 |
|
|---|
| 96 |
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`: |
|---|
| 97 |
|
|---|
| 98 |
{{{ |
|---|
| 99 |
all: |
|---|
| 100 |
sfPropelSpamTagBehavior: |
|---|
| 101 |
display_treshold: 0 # Only allow records marked TAGGED_SAFE |
|---|
| 102 |
#display_treshold: 1 # Allow records marked TAGGED_SAFE, and NOT_CHECKED |
|---|
| 103 |
#display_treshold: 2 # Allow records marked TAGGED_SAFE, NOT_CHECKED, and TAGGED_AUTO_SPAM |
|---|
| 104 |
#display_treshold: 3 # Allow all records |
|---|
| 105 |
}}} |
|---|
| 106 |
|
|---|
| 107 |
With this setting, only records marked with `TAGGED_SAFE` are returned. |
|---|
| 108 |
|
|---|
| 109 |
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. |
|---|
| 110 |
|
|---|
| 111 |
{{{ |
|---|
| 112 |
$item = ItemPeer::retrieveByPk($id); // Returns null |
|---|
| 113 |
sfPropelSpamTagBehavior::disable(); |
|---|
| 114 |
$item = ItemPeer::retrieveByPk($id); // Returns an item |
|---|
| 115 |
}}} |
|---|
| 116 |
|
|---|
| 117 |
Don't forget to enable the behavior again afterwards: |
|---|
| 118 |
|
|---|
| 119 |
{{{ |
|---|
| 120 |
sfPropelSpamTagBehavior::enable(); |
|---|
| 121 |
}}} |
|---|
| 122 |
|
|---|
| 123 |
== Todo == |
|---|
| 124 |
|
|---|
| 125 |
* Add a Report table to allow users to complain about a content (hash between user_id, object_id and object_class) |
|---|
| 126 |
* Add lists for moderators (reported content, latest published content, latest spammed content) |
|---|
| 127 |
* Add a batch to remove old contents marked as spam |
|---|
| 128 |
|
|---|
| 129 |
== Changelog == |
|---|
| 130 |
|
|---|
| 131 |
=== Trunk === |
|---|
| 132 |
|
|---|
| 133 |
=== 2007-09-09 | 0.9.1 Beta === |
|---|
| 134 |
|
|---|
| 135 |
* francois: Added unit tests |
|---|
| 136 |
* francois: Improved documentation |
|---|
| 137 |
* francois: Added getter and setter for spam tag column |
|---|
| 138 |
* francois: [Break BC] changed the spam column to a four-state integer field |
|---|
| 139 |
* francois: Added support for a priori and a posteriori moderation |
|---|
| 140 |
* francois: Made the plugin compatible with symfony 1.0 |
|---|
| 141 |
|
|---|
| 142 |
=== 2007-03-23 | 0.9.0 Beta === |
|---|
| 143 |
|
|---|
| 144 |
* francois: Initial release |
|---|