[pLog-svn] r3345 - in plugins/trunk/hostblock/class: action dao
security
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Fri May 5 20:54:30 GMT 2006
Author: oscar
Date: 2006-05-05 20:54:30 +0000 (Fri, 05 May 2006)
New Revision: 3345
Modified:
plugins/trunk/hostblock/class/action/adminaddblockedhostaction.class.php
plugins/trunk/hostblock/class/action/adminaddblogblockedhostaction.class.php
plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php
plugins/trunk/hostblock/class/action/admindeleteblogblockedhostaction.class.php
plugins/trunk/hostblock/class/action/adminupdateblockedhostaction.class.php
plugins/trunk/hostblock/class/action/adminupdateblockedhostsettingsaction.class.php
plugins/trunk/hostblock/class/action/adminupdateblogblockedhostaction.class.php
plugins/trunk/hostblock/class/dao/blockedhost.class.php
plugins/trunk/hostblock/class/dao/blockedhosts.class.php
plugins/trunk/hostblock/class/security/hostsblacklist.class.php
Log:
major cleanup and adapted the plugin to the new caching framework so that the same queries are not repeated over and over again
Modified: plugins/trunk/hostblock/class/action/adminaddblockedhostaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/adminaddblockedhostaction.class.php 2006-05-05 20:37:34 UTC (rev 3344)
+++ plugins/trunk/hostblock/class/action/adminaddblockedhostaction.class.php 2006-05-05 20:54:30 UTC (rev 3345)
@@ -5,6 +5,7 @@
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/dao/blockedhosts.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminnewblockedhostview.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblockedhostsview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
/**
* Adds new blocked content to the whole site
@@ -34,7 +35,7 @@
$this->_form->registerField( "blockType" );
$this->_form->registerField( "reason" );
- $view = new AdminNewBlockedHostView( $this->_blogInfo, $this->_hostId );
+ $view = new AdminNewBlockedHostView( $this->_blogInfo );
$view->setErrorMessage( $this->_locale->tr("error_provide_host_to_block" ));
$this->setValidationErrorView( $view );
}
Modified: plugins/trunk/hostblock/class/action/adminaddblogblockedhostaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/adminaddblogblockedhostaction.class.php 2006-05-05 20:37:34 UTC (rev 3344)
+++ plugins/trunk/hostblock/class/action/adminaddblogblockedhostaction.class.php 2006-05-05 20:54:30 UTC (rev 3345)
@@ -4,7 +4,8 @@
include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/dao/blockedhosts.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminnewblogblockedhostview.class.php" );
- include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblogblockedhostsview.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblogblockedhostsview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
/**
* Adds new blocked content to the blog
@@ -34,9 +35,9 @@
$this->_form->registerField( "blockType" );
$this->_form->registerField( "reason" );
- $view = new AdminNewBlogBlockedHostView( $this->_blogInfo, $this->_hostId );
+ $view = new AdminNewBlogBlockedHostView( $this->_blogInfo );
$view->setErrorMessage( $this->_locale->tr("error_provide_host_to_block" ));
- $this->setValidationErrorView( $view );
+ $this->setValidationErrorView( $view );
}
function perform()
Modified: plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php 2006-05-05 20:37:34 UTC (rev 3344)
+++ plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php 2006-05-05 20:54:30 UTC (rev 3345)
@@ -5,6 +5,7 @@
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/dao/blockedhosts.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminnewblockedhostview.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblockedhostsview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
/**
* Deletes a post from the database
Modified: plugins/trunk/hostblock/class/action/admindeleteblogblockedhostaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/admindeleteblogblockedhostaction.class.php 2006-05-05 20:37:34 UTC (rev 3344)
+++ plugins/trunk/hostblock/class/action/admindeleteblogblockedhostaction.class.php 2006-05-05 20:54:30 UTC (rev 3345)
@@ -2,6 +2,7 @@
include_once( PLOG_CLASS_PATH."class/action/admin/blogowneradminaction.class.php" );
include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/dao/blockedhosts.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminnewblogblockedhostview.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblogblockedhostsview.class.php" );
Modified: plugins/trunk/hostblock/class/action/adminupdateblockedhostaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/adminupdateblockedhostaction.class.php 2006-05-05 20:37:34 UTC (rev 3344)
+++ plugins/trunk/hostblock/class/action/adminupdateblockedhostaction.class.php 2006-05-05 20:54:30 UTC (rev 3345)
@@ -5,6 +5,7 @@
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/dao/blockedhosts.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/admineditblockedhostview.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblockedhostsview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
/**
* Changes the settings of a blocked host
Modified: plugins/trunk/hostblock/class/action/adminupdateblockedhostsettingsaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/adminupdateblockedhostsettingsaction.class.php 2006-05-05 20:37:34 UTC (rev 3344)
+++ plugins/trunk/hostblock/class/action/adminupdateblockedhostsettingsaction.class.php 2006-05-05 20:54:30 UTC (rev 3345)
@@ -2,7 +2,7 @@
include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
- include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblockedhostsettingsview.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblockedhostsettingsview.class.php" );
/**
* updates the plugin configuration
Modified: plugins/trunk/hostblock/class/action/adminupdateblogblockedhostaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/adminupdateblogblockedhostaction.class.php 2006-05-05 20:37:34 UTC (rev 3344)
+++ plugins/trunk/hostblock/class/action/adminupdateblogblockedhostaction.class.php 2006-05-05 20:54:30 UTC (rev 3345)
@@ -4,7 +4,8 @@
include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/dao/blockedhosts.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/admineditblogblockedhostview.class.php" );
- include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblogblockedhostsview.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblogblockedhostsview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
/**
* Changes the settings of a blocked host
Modified: plugins/trunk/hostblock/class/dao/blockedhost.class.php
===================================================================
--- plugins/trunk/hostblock/class/dao/blockedhost.class.php 2006-05-05 20:37:34 UTC (rev 3344)
+++ plugins/trunk/hostblock/class/dao/blockedhost.class.php 2006-05-05 20:54:30 UTC (rev 3345)
@@ -24,7 +24,7 @@
/**
* Represents a record from the plog_blocked_hosts table.
*/
- class BlockedHost
+ class BlockedHost extends DbObject
{
var $_id;
@@ -37,9 +37,7 @@
var $_blockList;
function BlockedHost( $host, $mask, $reason, $date, $blogId, $blockType, $blockList, $id = 1 )
- {
-
-
+ {
$this->_host = $host;
$this->_mask = $mask;
$this->_reason = $reason;
@@ -48,7 +46,23 @@
$this->_blockType = $blockType;
$this->_blockList = $blockList;
$this->_id = $id;
+
+ $this->_fields = Array(
+ "id" => "getId",
+ "reason" => "getReason",
+ "host" => "getHost",
+ "mask" => "getMask",
+ "date" => "getDateObject",
+ "blog_id" => "getBlogId",
+ "block_type" => "getType",
+ "list_type" => "getBlockList",
+ );
}
+
+ function setId( $id )
+ {
+ $this->_id = $id;
+ }
/**
* Returns only the string representing the ip, without the mask
@@ -90,7 +104,7 @@
function getDateObject()
{
- return new Timestamp( $this->_date);
+ return( new Timestamp( $this->_date));
}
/**
Modified: plugins/trunk/hostblock/class/dao/blockedhosts.class.php
===================================================================
--- plugins/trunk/hostblock/class/dao/blockedhosts.class.php 2006-05-05 20:37:34 UTC (rev 3344)
+++ plugins/trunk/hostblock/class/dao/blockedhosts.class.php 2006-05-05 20:54:30 UTC (rev 3345)
@@ -2,6 +2,9 @@
include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
include_once( PLOG_CLASS_PATH."plugins/hostblock/class/dao/blockedhost.class.php" );
+
+ define( "CACHE_BLOCKEDHOSTS_BLOG", "blockedhosts_blog" );
+ define( "CACHE_BLOCKEDHOSTS", "blockedhosts" );
/**
* Class that implements the data access model to read information about the
@@ -14,23 +17,31 @@
function BlockedHosts()
{
$this->Model();
+
+ $this->table = $this->getPrefix()."host_blocking_rules";
}
function getBlockedHost( $id, $blogId = 0 )
{
- $query = "SELECT * FROM ".$this->getPrefix()."host_blocking_rules ".
- "WHERE id = $id";
- if( $blogId > 0 )
- $query .= " AND blog_id = $blogId";
+ $block = $this->get( "id", $id, CACHE_BLOCKEDHOSTS );
+ if( $blogId > -1 )
+ if( $block->getBlogId() != $blogId )
+ return false;
+
+ return( $block );
+ }
- $result = $this->Execute( $query );
-
- if( !$result )
- return false;
-
- $row = $result->FetchRow();
-
- return $this->_fillBlockedHostInformation( $row );
+ /**
+ * Returns all the globally blacklisted hosts
+ *
+ * @param blockType Wether we'd like to fetch only those hosts that have
+ * been blocked from posting comments (BLOCK_COMMENT_POSTING), from accesing the
+ * site completely (BLOCK_ACCESS)
+ * @return An array of BlockedHost objects with all the information necessary.
+ */
+ function getGlobalBlacklist( $blockType = BLOCK_COMMENT_POSTING )
+ {
+ return( $this->getBlogBlacklist( 0, $blockType, false ));
}
/**
@@ -42,30 +53,27 @@
* site completely (BLOCK_ACCESS)
* @param includeGlobal 'true' if we'd like the function to return the hosts that
* have been blocked by the given blog *AND* the global ones.
- * @return An array of BlockeHost objects with all the information necessary.
+ * @return An array of BlockedHost objects with all the information necessary.
*/
function getBlogBlacklist( $blogId, $blockType = BLOCK_COMMENT_POSTING, $includeGlobal = false )
- {
- $query = "SELECT * FROM ".$this->getPrefix()."host_blocking_rules WHERE";
-
- if( $includeGlobal )
- $query .=" blog_id IN ('".Db::qstr( $blogId )."', '".GLOBALLY_BLOCKED_HOST."') ";
- else
- $query .= " blog_id = '".Db::qstr( $blogId )."'";
-
- $query .= " AND block_type = $blockType";
-
- $result = $this->Execute( $query );
-
- if( !$result )
- return false;
-
+ {
+ $data = Array();
$blockedHosts = Array();
- while( $row = $result->FetchRow()) {
- array_push( $blockedHosts, $this->_fillBlockedHostInformation( $row ));
+
+ $data = $this->getMany( "blog_id", $blogId, CACHE_BLOCKEDHOSTS_BLOG );
+ if( $data ) {
+ foreach( $data as $host ) {
+ if( $host->getType() == $blockType )
+ $blockedHosts[] = $host;
+ }
}
-
- return $blockedHosts;
+
+ if( $includeGlobal ) {
+ /** merge this data with the globally blocked hosts **/
+ $blockedHosts = array_merge( $blockedHosts, $this->getBlogBlacklist( "0", $blockType, false ));
+ }
+
+ return( $blockedHosts );
}
/**
@@ -77,48 +85,59 @@
*/
function add( $blockedHost )
{
- $query = "INSERT INTO ".$this->getPrefix()."host_blocking_rules
- (host, mask, blog_id, block_type, list_type, reason) VALUES (".
- "'".$blockedHost->getHost()."', ".$blockedHost->getMask().
- ", ".$blockedHost->getBlogId().", ".$blockedHost->getType().
- ", ".$blockedHost->getBlockList().", '".Db::qstr($blockedHost->getReason())."' )";
-
- $result = $this->Execute( $query );
-
- return $result;
+ if( $result = parent::add( $blockedHost )) {
+ if( $blockedHost->isGlobal())
+ $id = 0;
+ else
+ $id = $blockedHost->getBlogId();
+
+ // clean the cache with the right id
+ $this->_cache->removeData( $id, CACHE_BLOCKEDHOSTS_BLOG );
+ }
+
+ return( $result );
}
+ /**
+ * removes a blocked host from the db
+ *
+ * @param id
+ * @param blogId
+ * @return True if successful or false otherwise
+ */
function remove( $id, $blogId = -1 )
{
- $query = "DELETE FROM ".$this->getPrefix()."host_blocking_rules
- WHERE id = $id";
- if( $blogId != -1 )
- $query .= " AND blog_id = $blogId";
-
- $result = $this->Execute( $query );
-
+ $block = $this->getBlockedHost( $id, $blogId );
+ if( $blogId > -1 )
+ if( $block->getBlogId() != $blogId )
+ return false;
+
+ if(( $result = $this->delete( "id", $id ))) {
+ $this->_cache->removeData( $block->getBlogId(), CACHE_BLOCKEDHOSTS_BLOG );
+ }
+
return $result;
}
+ /**
+ * updates a blocked host
+ *
+ * @param blockedHost
+ */
function update( $blockedHost )
- {
- $query = "UPDATE ".$this->getPrefix()."host_blocking_rules
- SET host = '".$blockedHost->getHost()."',
- mask = ".$blockedHost->getMask().",
- blog_id = ".$blockedHost->getBlogId().",
- block_type = ".$blockedHost->getType().",
- reason = '".Db::qstr($blockedHost->getReason())."'
- WHERE id = ".$blockedHost->getId();
-
- $result = $this->Execute( $query );
-
- return $result;
+ {
+ if(( $result = parent::update( $blockedHost ))) {
+ $this->_cache->removeData( $blockedHost->getBlogId(), CACHE_BLOCKEDHOSTS_BLOG );
+ $this->_cache->removeData( $blockedHost->getId(), CACHE_BLOCKEDHOSTS );
+ }
+
+ return( $result );
}
/**
* @private
*/
- function _fillBlockedHostInformation( $row )
+ function mapRow( $row )
{
$blockedHost = new BlockedHost( $row["host"],
$row["mask"],
Modified: plugins/trunk/hostblock/class/security/hostsblacklist.class.php
===================================================================
--- plugins/trunk/hostblock/class/security/hostsblacklist.class.php 2006-05-05 20:37:34 UTC (rev 3344)
+++ plugins/trunk/hostblock/class/security/hostsblacklist.class.php 2006-05-05 20:54:30 UTC (rev 3345)
@@ -39,7 +39,7 @@
// get the list of blocked hosts for this blog
$blockedHosts = new BlockedHosts();
- $hostsAccessBlocked = $blockedHosts->getBlogBlacklist( $blogInfo->getId(), BLOCK_ACCESS, true );
+ $hostsAccessBlocked = $blockedHosts->getBlogBlacklist( $blogInfo->getId(), BLOCK_ACCESS, true );
$hostsPostCommentBlocked = $blockedHosts->getBlogBlacklist( $blogInfo->getId(), BLOCK_COMMENT_POSTING, true );
// and now check one by one, comparing with the ip we just got
More information about the pLog-svn
mailing list