Changeset 5013
- Timestamp:
- 09/09/07 11:09:36 (6 years ago)
- Files:
-
- plugins/sfPropelSpamTagBehaviorPlugin/README (modified) (2 diffs)
- plugins/sfPropelSpamTagBehaviorPlugin/config/config.php (modified) (2 diffs)
- plugins/sfPropelSpamTagBehaviorPlugin/lib/SfPeerBuilder.php (added)
- plugins/sfPropelSpamTagBehaviorPlugin/lib/sfPropelSpamTagBehavior.class.php (modified) (1 diff)
- plugins/sfPropelSpamTagBehaviorPlugin/package.xml (modified) (2 diffs)
- plugins/sfPropelSpamTagBehaviorPlugin/test (added)
- plugins/sfPropelSpamTagBehaviorPlugin/test/unit (added)
- plugins/sfPropelSpamTagBehaviorPlugin/test/unit/sfPropelSpamTagBehaviorTest.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelSpamTagBehaviorPlugin/README
r4571 r5013 8 8 == Installation == 9 9 10 This plugin requires an updated version of the symfony libraries. The 1.0 branch contains a bug in the Propel hooks, fixed in the trunk (changeset 3663), which prevents some behaviors from properly working. So you can only use this plugin if your project uses the trunk version of symfony.11 12 10 * Install the plugin 13 11 14 {{{15 symfony plugin-install http://plugins.symfony-project.com/sfPropelSpamTagBehaviorPlugin16 }}}12 {{{ 13 $ symfony plugin-install http://plugins.symfony-project.com/sfPropelSpamTagBehaviorPlugin 14 }}} 17 15 18 16 * Enable Propel behavior support in `propel.ini`: 19 17 20 {{{ 21 propel.builder.AddBehaviors = true 22 }}} 23 24 If you have to enable the behavior support, rebuild your model: 18 {{{ 19 propel.builder.AddBehaviors = true 20 }}} 25 21 26 {{{ 27 symfony propel-build-model 28 }}} 22 * If you use symfony 1.0, change one builder class in `propel.ini` to avoid a bug in behaviors (not necessary in sf1.1): 29 23 30 * Activate the behavior for one of your Propel model: 24 {{{ 25 ; builder settings 26 propel.builder.peer.class = plugins.sfPropelSpamTagBehaviorPlugin.lib.SfPeerBuilder 27 }}} 31 28 32 {{{ 33 // lib/model/Comment.php 34 class Comment 35 { 36 } 29 * 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` 37 30 38 sfPropelBehavior::add('Comment', array('spamTag')); 39 }}} 31 {{{ 32 propel: 33 item: 34 id: 35 title: varchar(255) 36 body: longvarchar 37 created_at: 38 updated_at: 39 moderation_status: { type: integer, default: 1, index: true } # Add this column to each table 40 }}} 40 41 41 By default, the plugin will consider the `is_spam` column for this model. You can also specify another column:42 * Activate the behavior for those of your Propel models that need spam moderation: 42 43 43 {{{ 44 sfPropelBehavior::add('Comment', array('spamTag' => array('column' => 'tagged_as_spam'))); 45 }}} 44 {{{ 45 // lib/model/Item.php 46 class Item 47 { 48 } 49 50 sfPropelBehavior::add('Item', array('spam_tag')); 51 }}} 52 53 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: 54 55 {{{ 56 sfPropelBehavior::add('Item', array('spam_tag' => array('column' => 'my_spam_tag'))); 57 }}} 58 59 Note that the column must still be an integer with default value equal to '1'. 60 61 * Rebuild your model: 62 63 {{{ 64 $ symfony propel-build-model 65 }}} 46 66 47 67 == Usage == 48 68 49 Here are some examples of Propel calls and the generated SQL: 69 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. 50 70 51 71 {{{ 52 $articles = CommentPeer::doSelect(new Criteria()); 53 // Generates in SQL 54 SELECT blog_comment.ID, blog_comment.AUTHOR_ID, blog_comment.CREATED_AT, blog_article.BODY, blog_article.IS_SPAM FROM blog_comment 55 WHERE blog_comment.IS_SPAM = 0 56 57 $article = Comment::retrieveByPK(1); 58 // Generates in SQL 59 SELECT blog_comment.ID, blog_comment.AUTHOR_ID, blog_comment.CREATED_AT, blog_article.BODY, blog_article.IS_SPAM FROM blog_comment 60 WHERE blog_comment.ID=1 AND blog_comment.IS_SPAM = 0 61 62 $articles = CommentPeer::doCount(new Criteria()); 63 // Generates in SQL 64 SELECT COUNT(blog_comment.ID) FROM blog_comment WHERE blog_comment.IS_SPAM = 0 72 $item = new Item(); 73 $item->save(); 74 $id = $item->getId(); 75 $item->tagAsSpam(); 76 $item = ItemPeer::retrieveByPk($id); // Returns null 65 77 }}} 66 78 67 You can also disable the behavior with:79 You can inspect the spam tag of any object through the `getSpamTag()` method. 68 80 69 81 {{{ 70 sfPropelSpamTagBehavior::disable(); 82 $spam_tag = $item->getSpamTag(); 83 switch($spam_tag) 84 { 85 case sfPropelSpamTagBehavior::TAGGED_SAFE: 86 echo "The item has been checked and marked as safe"; 87 break; 88 case sfPropelSpamTagBehavior::NOT_CHECKED: 89 echo "The item is not yet checked"; 90 break; 91 case sfPropelSpamTagBehavior::TAGGED_AUTO_SPAM: 92 echo "The item has been checked by an automated service and marked as spam"; 93 break; 94 case sfPropelSpamTagBehavior::TAGGED_SPAM: 95 echo "The item has been checked and marked as spam"; 96 } 71 97 }}} 72 98 73 This ill allow you to query the database for tagged records. Don't forget to enable the behavior again afterwards: 99 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`: 100 101 {{{ 102 all: 103 sfPropelSpamTagBehavior: 104 display_treshold: 0 # Only allow records marked TAGGED_SAFE 105 #display_treshold: 1 # Allow records marked TAGGED_SAFE, and NOT_CHECKED 106 #display_treshold: 2 # Allow records marked TAGGED_SAFE, NOT_CHECKED, and TAGGED_AUTO_SPAM 107 #display_treshold: 3 # Allow all records 108 }}} 109 110 With this setting, only records marked with `TAGGED_SAFE` are returned. 111 112 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. 113 114 {{{ 115 $item = ItemPeer::retrieveByPk($id); // Returns null 116 sfPropelSpamTagBehavior::disable(); 117 $item = ItemPeer::retrieveByPk($id); // Returns an item 118 }}} 119 120 Don't forget to enable the behavior again afterwards: 74 121 75 122 {{{ … … 77 124 }}} 78 125 126 == Todo == 127 128 * Add a Report table to allow users to complain about a content (hash between user_id, object_id and object_class) 129 * Add lists for moderators (reported content, latest published content, latest spammed content) 130 * Add a batch to remove old contents marked as spam 131 79 132 == Changelog == 133 134 === Trunk === 135 136 === 2007-09-09 | 0.9.1 Beta === 137 138 * francois: Added unit tests 139 * francois: Improved documentation 140 * francois: Added getter and setter for spam tag column 141 * francois: [Break BC] changed the spam column to a four-state integer field 142 * francois: Added support for a priori and a posteriori moderation 143 * francois: Made the plugin compatible with symfony 1.0 80 144 81 145 === 2007-03-23 | 0.9.0 Beta === plugins/sfPropelSpamTagBehaviorPlugin/config/config.php
r3664 r5013 1 1 <?php 2 2 3 sfPropelBehavior::registerHooks('spam Tag',3 sfPropelBehavior::registerHooks('spam_tag', 4 4 array( 5 5 'Peer:doSelectRS' => array( … … 18 18 ); 19 19 20 sfPropelBehavior::registerMethods('spam_tag', array( 21 array ('sfPropelSpamTagBehavior', 'tagAsSpam'), 22 array ('sfPropelSpamTagBehavior', 'tagAsSafe'), 23 array ('sfPropelSpamTagBehavior', 'getSpamTag'), 24 array ('sfPropelSpamTagBehavior', 'setSpamTag') 25 )); 26 plugins/sfPropelSpamTagBehaviorPlugin/lib/sfPropelSpamTagBehavior.class.php
r3664 r5013 3 3 class sfPropelSpamTagBehavior 4 4 { 5 const TAGGED_SAFE = 0; 6 const NOT_CHECKED = 1; 7 const TAGGED_AUTO_SPAM = 2; 8 const TAGGED_SPAM = 3; 9 5 10 static protected $isActivated = true; 6 11 7 12 public function updateCriteria($class , $myCriteria, $con = null) 8 13 { 9 $columnName = sfConfig::get('propel_behavior_spam Tag_'.$class.'_column', 'is_spam');14 $columnName = sfConfig::get('propel_behavior_spam_tag_'.$class.'_column', 'moderation_status'); 10 15 11 16 if (self::$isActivated) 12 17 { 13 $myCriteria->add(call_user_func(array($class, 'translateFieldName'), $columnName, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME), false); 18 $myCriteria->add( 19 call_user_func(array($class, 'translateFieldName'), $columnName, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME), 20 sfConfig::get('app_sfPropelSpamTagBehavior_display_treshold', self::NOT_CHECKED), 21 Criteria::LESS_EQUAL 22 ); 14 23 } 15 24 } 16 25 26 public function tagAsSpam($object, $type = 'manual') 27 { 28 self::setSpamTag( 29 $object, 30 ($type == 'manual') ? self::TAGGED_SPAM : self::TAGGED_AUTO_SPAM 31 ); 32 33 return $object->save(); 34 } 35 36 public function tagAsSafe($object) 37 { 38 self::setSpamTag($object, self::TAGGED_SAFE); 39 40 return $object->save(); 41 } 42 43 public function getSpamTag($object) 44 { 45 return $object->getByName(sfConfig::get('propel_behavior_spam_tag_'.get_class($object).'_column', 'moderation_status'), BasePeer::TYPE_FIELDNAME); 46 } 47 48 public function setSpamTag($object, $value) 49 { 50 return $object->setByName( 51 sfConfig::get('propel_behavior_spam_tag_'.get_class($object).'_column', 'moderation_status'), 52 $value, 53 BasePeer::TYPE_FIELDNAME 54 ); 55 } 56 17 57 static public function enable() 18 58 { plugins/sfPropelSpamTagBehaviorPlugin/package.xml
r3857 r5013 11 11 <active>yes</active> 12 12 </lead> 13 <date>2007-0 3-23</date>13 <date>2007-09-09</date> 14 14 <version> 15 <release>0.9. 0</release>16 <api>0.9. 0</api>15 <release>0.9.1</release> 16 <api>0.9.1</api> 17 17 </version> 18 18 <stability> … … 25 25 <dir name="/"> 26 26 <file name="config/config.php" role="data" /> 27 <file name="lib/SfPeerBuilder.php" role="data" /> 27 28 <file name="lib/sfPropelSpamTagBehavior.class.php" role="data" /> 29 <file name="test/unit/sfPropelSpamTagBehaviorTest.php" role="data" /> 28 30 <file name="README" role="data" /> 29 31 <file name="LICENSE" role="data" />