Development

Changeset 5013 for plugins/sfPropelSpamTagBehaviorPlugin

You must first sign up to be able to contribute.

Show
Ignore:
Timestamp:
09/09/07 11:09:36 (6 years ago)
Author:
francois
Message:

sfPropelSpamTagBehaviorPlugin Releasing 0.9.1 (see README for details)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelSpamTagBehaviorPlugin/README

    r4571 r5013  
    88== Installation == 
    99 
    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  
    1210  * Install the plugin 
    1311   
    14     {{{ 
    15       symfony plugin-install http://plugins.symfony-project.com/sfPropelSpamTagBehaviorPlugin 
    16     }}} 
     12{{{ 
     13$ symfony plugin-install http://plugins.symfony-project.com/sfPropelSpamTagBehaviorPlugin 
     14}}} 
    1715 
    1816  * Enable Propel behavior support in `propel.ini`: 
    1917 
    20     {{{ 
    21       propel.builder.AddBehaviors = true 
    22     }}} 
    23    
    24     If you have to enable the behavior support, rebuild your model: 
     18{{{ 
     19propel.builder.AddBehaviors = true 
     20}}} 
    2521 
    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): 
    2923 
    30   * Activate the behavior for one of your Propel model: 
     24{{{ 
     25; builder settings 
     26propel.builder.peer.class = plugins.sfPropelSpamTagBehaviorPlugin.lib.SfPeerBuilder 
     27}}} 
    3128 
    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` 
    3730 
    38       sfPropelBehavior::add('Comment', array('spamTag')); 
    39     }}} 
     31{{{ 
     32propel: 
     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}}} 
    4041 
    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: 
    4243 
    43     {{{ 
    44       sfPropelBehavior::add('Comment', array('spamTag' => array('column' => 'tagged_as_spam'))); 
    45     }}} 
     44{{{ 
     45// lib/model/Item.php 
     46class Item 
     47
     48
     49 
     50sfPropelBehavior::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{{{ 
     56sfPropelBehavior::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}}} 
    4666 
    4767== Usage == 
    4868 
    49 Here are some examples of Propel calls and the generated SQL: 
     69If 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. 
    5070 
    5171{{{ 
    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 
    6577}}} 
    6678 
    67 You can also disable the behavior with: 
     79You can inspect the spam tag of any object through the `getSpamTag()` method. 
    6880 
    6981{{{ 
    70   sfPropelSpamTagBehavior::disable(); 
     82$spam_tag = $item->getSpamTag(); 
     83switch($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
    7197}}} 
    7298 
    73 This ill allow you to query the database for tagged records. Don't forget to enable the behavior again afterwards: 
     99By 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{{{ 
     102all: 
     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 
     110With this setting, only records marked with `TAGGED_SAFE` are returned.  
     111 
     112The 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 
     116sfPropelSpamTagBehavior::disable(); 
     117$item = ItemPeer::retrieveByPk($id);   // Returns an item 
     118}}} 
     119 
     120Don't forget to enable the behavior again afterwards: 
    74121 
    75122{{{ 
     
    77124}}} 
    78125 
     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 
    79132== 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 
    80144 
    81145=== 2007-03-23 | 0.9.0 Beta === 
  • plugins/sfPropelSpamTagBehaviorPlugin/config/config.php

    r3664 r5013  
    11<?php 
    22 
    3 sfPropelBehavior::registerHooks('spamTag',  
     3sfPropelBehavior::registerHooks('spam_tag',  
    44  array( 
    55    'Peer:doSelectRS' => array(  
     
    1818); 
    1919 
     20sfPropelBehavior::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  
    33class sfPropelSpamTagBehavior 
    44{ 
     5  const TAGGED_SAFE      = 0; 
     6  const NOT_CHECKED      = 1; 
     7  const TAGGED_AUTO_SPAM = 2; 
     8  const TAGGED_SPAM      = 3; 
     9   
    510  static protected $isActivated = true; 
    611 
    712  public function updateCriteria($class , $myCriteria, $con = null) 
    813  { 
    9     $columnName = sfConfig::get('propel_behavior_spamTag_'.$class.'_column', 'is_spam'); 
     14    $columnName = sfConfig::get('propel_behavior_spam_tag_'.$class.'_column', 'moderation_status'); 
    1015 
    1116    if (self::$isActivated) 
    1217    { 
    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      ); 
    1423    } 
    1524  } 
    1625 
     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   
    1757  static public function enable() 
    1858  { 
  • plugins/sfPropelSpamTagBehaviorPlugin/package.xml

    r3857 r5013  
    1111  <active>yes</active> 
    1212 </lead> 
    13  <date>2007-03-23</date> 
     13 <date>2007-09-09</date> 
    1414 <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> 
    1717 </version> 
    1818 <stability> 
     
    2525  <dir name="/"> 
    2626   <file name="config/config.php" role="data" /> 
     27   <file name="lib/SfPeerBuilder.php" role="data" /> 
    2728   <file name="lib/sfPropelSpamTagBehavior.class.php" role="data" /> 
     29   <file name="test/unit/sfPropelSpamTagBehaviorTest.php" role="data" /> 
    2830   <file name="README" role="data" /> 
    2931   <file name="LICENSE" role="data" />