[pLog-svn] r869 - in plugins/trunk/hostblock: class/action templates

mark at devel.plogworld.net mark at devel.plogworld.net
Fri Jan 28 08:46:30 GMT 2005


Author: mark
Date: 2005-01-28 08:46:29 +0000 (Fri, 28 Jan 2005)
New Revision: 869

Modified:
   plugins/trunk/hostblock/class/action/adminaddblockedhostaction.class.php
   plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php
   plugins/trunk/hostblock/class/action/adminupdateblockedhostaction.class.php
   plugins/trunk/hostblock/templates/addblockedhost.template
Log:


Modified: plugins/trunk/hostblock/class/action/adminaddblockedhostaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/adminaddblockedhostaction.class.php	2005-01-28 06:35:24 UTC (rev 868)
+++ plugins/trunk/hostblock/class/action/adminaddblockedhostaction.class.php	2005-01-28 08:46:29 UTC (rev 869)
@@ -1,10 +1,10 @@
 <?php
 
 	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
-    include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
-    include_once( PLOG_CLASS_PATH."class/view/admin/adminmessageview.class.php" );    
     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/adminnewblockedhostview.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblockedhostsview.class.php" );    
 
     /**
      * Adds new blocked content to the whole site
@@ -24,32 +24,34 @@
     	function AdminAddBlockedHostAction( $actionInfo, $request )
         {
         	$this->SiteAdminAction( $actionInfo, $request );
-        }
+        	
+			// set up the data validators
+			// data validation
+			$this->registerFieldValidator( "ip1", new IntegerValidator());
+			$this->registerFieldValidator( "ip2", new IntegerValidator());
+			$this->registerFieldValidator( "ip3", new IntegerValidator());
+			$this->registerFieldValidator( "ip4", new IntegerValidator());
+			$this->_form->registerField( "mask" );
+			$this->_form->registerField( "blockType" );			
+			$this->_form->registerField( "reason" );
 
-        function validate()
-        {
-        	// get the fields
-        	$this->_ip1 = $this->_request->getValue( "ip1" );
-            $this->_ip2 = $this->_request->getValue( "ip2" );
-            $this->_ip3 = $this->_request->getValue( "ip3" );
-            $this->_ip4 = $this->_request->getValue( "ip4" );
-            // and build up the ip address
-            $this->_hostIp = $this->_ip1.".".$this->_ip2.".".$this->_ip3.".".$this->_ip4;
-
-            // fetch the reason
-            $this->_reason = $this->_request->getValue( "reason" );
-
-            // and the type
-            $this->_blockType = $this->_request->getValue( "blockType" );
-
-			// finally, the mask
-			$this->_mask = $this->_request->getValue( "mask" );
-
-            return true;
+			$view = new AdminNewBlockedHostView( $this->_blogInfo, $this->_hostId );
+			$view->setErrorMessage( $this->_locale->tr("error_provide_host_to_block" ));
+			$this->setValidationErrorView( $view );           	
         }
 
         function perform()
         {
+        	// fetch the data
+            $this->_ip1         = $this->_request->getValue( "ip1" );
+            $this->_ip2         = $this->_request->getValue( "ip2" );
+            $this->_ip3         = $this->_request->getValue( "ip3" );
+            $this->_ip4         = $this->_request->getValue( "ip4" );
+            $this->_hostIp      = $this->_ip1.".".$this->_ip2.".".$this->_ip3.".".$this->_ip4;
+            $this->_mask        = $this->_request->getValue( "mask" );
+            $this->_blockType   = $this->_request->getValue( "blockType" );
+            $this->_reason      = $this->_request->getValue( "reason" );
+
         	// create the dao object and add the info to the db
             $blockedHosts = new BlockedHosts();
 			$t = new Timestamp();
@@ -61,20 +63,17 @@
 
             // and give some feedback to the user
             if( !$result ) {
-            	$message = $this->_locale->tr("error_adding_blocked_host");
-				$message .= "<br/><br/><a href=\javascript:history.go(-1);\">".$this->_locale->tr("back")."</a>";
-                $this->_view = new AdminErrorView( $this->_blogInfo );
+            	$this->_view = new AdminNewBlockedHostView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("error_adding_blocked_host") );
+                $this->setCommonData();
+
+                return false;                  
             }
-            else {
-				$message = $this->_locale->pr("blocked_host_added_ok", $this->_hostIp );
-				$message .= "<br/><br/><a href=\"admin.php?op=blockedHosts\">".$this->_locale->tr("back")."</a>";
-                $this->_view = new AdminMessageView( $this->_blogInfo );
-				$this->notifyEvent( EVENT_POST_BLOCK_HOST_ADD, Array( "host" => &$blockedHost ));
-            }
+			$this->notifyEvent( EVENT_POST_BLOCK_HOST_ADD, Array( "host" => &$blockedHost ));
+          	$this->_view = new AdminBlockedHostsView( $this->_blogInfo );
+            $this->_view->setSuccessMessage( $this->_locale->tr("blocked_host_updated_ok") );
+            $this->setCommonData();            
 
-            $this->_view->setMessage( $message );
-            $this->setCommonData();
-
             return true;
         }
     }

Modified: plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php	2005-01-28 06:35:24 UTC (rev 868)
+++ plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php	2005-01-28 08:46:29 UTC (rev 869)
@@ -1,9 +1,10 @@
 <?php
 
 	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
-    include_once( PLOG_CLASS_PATH."class/view/admin/adminmessageview.class.php" );
-    include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
+    include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );    
     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" );      
 
     /**
      * Deletes a post from the database
@@ -12,6 +13,8 @@
 	{
 
     	var $_blockedIds;
+    	var $_hostId;
+    	var $_op;
 
     	/**
          * Constructor. If nothing else, it also has to call the constructor of the parent
@@ -20,57 +23,73 @@
         function AdminDeleteBlockedHostAction( $actionInfo, $request )
         {
         	$this->SiteAdminAction( $actionInfo, $request );
-        }
 
-        /**
-         * Validates that the information coming from the user is valid
-         */
-        function validate()
-        {
-            $this->_blockedIds = $this->_request->getValue( "deleteBlockedHost" );
-
-            if( count($this->_blockedIds) == 0 ) {
-                $this->_view = new AdminErrorView( $this->_blogInfo );
-				$message = $this->_locale->tr( "error_no_blocked_hosts_selected" );
-				$message .= "<br/><br/><a href=\"javascript:history.go(-1);\">".$this->_locale-tr("back")."</a>";
-                $this->_view->setValue( "message", $message );
-                $this->setCommonData();
-
-                return false;
-            }
-
-            return true;
+			$this->_op = $actionInfo->getActionParamValue();
+			
+			$view = new AdminBlockedHostsView( $this->_blogInfo );			
+			if( $this->_op == "deleteBlockedHost" ) {
+				$this->registerFieldValidator( "hostId", new IntegerValidator());
+				$view->setErrorMessage( $this->_locale->tr("error_incorrect_host_id"));	
+			}
+			else {
+				$this->registerFieldValidator( "deleteBlockedHost", new ArrayValidator());
+				$view->setErrorMessage( $this->_locale->tr("error_no_block_host_selected"));
+			}
+			$this->setValidationErrorView( $view );        	
         }
 
         /**
          * Carries out the specified action
          */
-        function perform()
+		function perform()
+		{
+			if( $this->_op == "deleteBlockedHost" ) {
+				$this->_blockedIds = Array();
+				$this->_hostId = $this->_request->getValue( "hostId" );
+				$this->_blockedIds[] = $this->_hostId;
+			}
+			else
+				$this->_blockedIds = $this->_request->getValue( "deleteBlockedHost" );
+				
+			$this->_deleteBlockedHosts();
+		}
+
+        function _deleteBlockedHosts()
         {
             $blockedHosts = new BlockedHosts();
-            $message = "";
+
+            // loop through the array of things to remove
+            $errorMessage = "";
+			$successMessage = "";
+			$numOk = 0;
             foreach( $this->_blockedIds as $blockedId ) {
             	// get the post
                 $blockedHost = $blockedHosts->getBlockedHost( $blockedId, GLOBALLY_BLOCKED_HOST );
 				$this->notifyEvent( EVENT_PRE_BLOCK_HOST_DELETE, Array( "host" => &$blockedHost ));				
             	$result = $blockedHosts->remove( $blockedId );
                 if( !$result )
-					$message .= $this->_locale->pr("error_deleting_blocked_host", $blockedHost->getHost());
+                    $errorMessage .= $this->_locale->pr("error_deleting_blocked_host", $blockedHost->getHost())."<br/>";
                 else {
-					$message .= $this->_locale->pr("blocked_host_deleted_ok", $blockedHost->getHost());
-					$this->notifyEvent( EVENT_POST_BLOCK_HOST_DELETE, Array( "host" => &$blockedHost ));					
+					$numOk++;
+					if( $numOk > 1 )
+						$successMessage = $this->_locale->pr("blocked_hosts_deleted_ok", $numOk );
+					else
+						$successMessage = $this->_locale->pr("blocked_host_deleted_ok", $blockedHost->getHost());
+					$this->notifyEvent( EVENT_POST_BLOCK_HOST_DELETE, Array( "host" => &$blockedHost ));
+										
 				}
-
-                $message .= "<br/><br/>";
             }
 
-
-            $this->_view = new AdminMessageView( $this->_blogInfo );
-			$message .= "<a href=\"admin.php?op=blockedHosts\">".$this->_locale->tr("back")."</a>";
-            $this->_view->setValue( "message", $message );
+            $this->_view = new AdminBlockedHostsView( $this->_blogInfo );
+            if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );
+			if( $successMessage != "" ) $this->_view->setSuccessMessage( $successMessage );
             $this->setCommonData();
+       
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());
 
-            return true;
+            // better to return true if everything fine
+            return true;            
 
         }
     }

Modified: plugins/trunk/hostblock/class/action/adminupdateblockedhostaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/adminupdateblockedhostaction.class.php	2005-01-28 06:35:24 UTC (rev 868)
+++ plugins/trunk/hostblock/class/action/adminupdateblockedhostaction.class.php	2005-01-28 08:46:29 UTC (rev 869)
@@ -1,9 +1,10 @@
 <?php
 
 	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
-    include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
-    include_once( PLOG_CLASS_PATH."class/view/admin/adminmessageview.class.php" );
+    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/admineditblockedhostview.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblockedhostsview.class.php" );     
 
     /**
      * Changes the settings of a blocked host
@@ -28,11 +29,33 @@
         function AdminUpdateBlockedHostAction( $actionInfo, $request )
         {
         	$this->SiteAdminAction( $actionInfo, $request );
+        	
+            // fetch the data
+            $this->_hostId = $this->_request->getValue( "hostId" );
+            
+			
+			// set up the data validators
+			// data validation
+			$this->registerFieldValidator( "hostId", new IntegerValidator());
+			$this->registerFieldValidator( "ip1", new IntegerValidator());
+			$this->registerFieldValidator( "ip2", new IntegerValidator());
+			$this->registerFieldValidator( "ip3", new IntegerValidator());
+			$this->registerFieldValidator( "ip4", new IntegerValidator());
+			$this->_form->registerField( "mask" );
+			$this->_form->registerField( "blockType" );			
+			$this->_form->registerField( "reason" );
+
+			$view = new AdminEditBlockedHostView( $this->_blogInfo, $this->_hostId );
+			$view->setErrorMessage( $this->_locale->tr("error_provide_host_to_block" ));
+			$this->setValidationErrorView( $view );         	
         }
 
-        function validate()
+        /**
+         * Carries out the specified action
+         */
+        function perform()
         {
-        	$this->_hostId = $this->_request->getValue( "hostId" );
+        	// fetch the data
             $this->_ip1    = $this->_request->getValue( "ip1" );
             $this->_ip2    = $this->_request->getValue( "ip2" );
             $this->_ip3    = $this->_request->getValue( "ip3" );
@@ -42,26 +65,16 @@
             $this->_type   = $this->_request->getValue( "blockType" );
             $this->_reason = $this->_request->getValue( "reason" );
 
-            return true;
-        }
-
-        /**
-         * Carries out the specified action
-         */
-        function perform()
-        {
         	$blockedHosts = new BlockedHosts();
             $blockedHost = $blockedHosts->getBlockedHost( $this->_hostId );
 
             // check if the info about the blocked host is correct
             if( !$blockedHost ) {
-            	$this->_view = new AdminErrorView( $this->_blogInfo );
-				$message = $this->_locale->tr( "error_fetching_blocked_host" );
-				$message .= "<br/><br/><a href=\"javascript:history.go(-1);\">".$this->_locale->tr("back")."</a>";				
-                $this->_view->setMessage( $message );
+            	$this->_view = new AdminBlockedHostsView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("error_fetching_blocked_host") );
                 $this->setCommonData();
 
-                return false;
+                return false;                   
             }
 
             // set the new information
@@ -71,22 +84,17 @@
             $blockedHost->setMask( $this->_mask );
 			$this->notifyEvent( EVENT_PRE_BLOCK_HOST_UPDATE, Array( "host" => &$blockedHost ));							
             if( !$blockedHosts->update( $blockedHost )) {
-            	$this->_view = new AdminErrorView( $this->_blogInfo );
-				$message = $this->_locale->tr( "error_updating_blocked_host" );
-				$message .= "<br/><br/><a href=\"javascript:history.go(-1);\">".$this->_locale->tr("back")."</a>";
-                $this->_view->setMessage( $message );
+            	$this->_view = new AdminBlockedHostsView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("error_updating_blocked_host") );
                 $this->setCommonData();
 
-                return false;
+                return false;                  
             }
 			$this->notifyEvent( EVENT_POST_BLOCK_HOST_UPDATE, Array( "host" => &$blockedHost ));
+          	$this->_view = new AdminBlockedHostsView( $this->_blogInfo );
+            $this->_view->setSuccessMessage( $this->_locale->tr("blocked_host_updated_ok") );
+            $this->setCommonData();            
 
-            $this->_view = new AdminMessageView( $this->_blogInfo );
-			$message = $this->_locale->tr("blocked_host_updated_ok" );
-			$message .= "<br/><br/><a href=\"admin.php?op=blockedHosts\">".$this->_locale->tr("back")."</a>";
-            $this->_view->setMessage( $message );
-            $this->setCommonData();
-
             return true;
         }
     }

Modified: plugins/trunk/hostblock/templates/addblockedhost.template
===================================================================
--- plugins/trunk/hostblock/templates/addblockedhost.template	2005-01-28 06:35:24 UTC (rev 868)
+++ plugins/trunk/hostblock/templates/addblockedhost.template	2005-01-28 08:46:29 UTC (rev 869)
@@ -11,9 +11,9 @@
    <span class="required">*</span>
    <div class="formHelp">{$locale->tr("host_to_block_help")}</div>
     <input style="width:40px;" type="text" size="3" maxlength="3" name="ip1" id="ip1" />.
-    <input style="width:40px;" type="text" size="3" maxlength="3" name="ip2" id="ip1" />.
-    <input style="width:40px;" type="text" size="3" maxlength="3" name="ip3" id="ip1" />.
-    <input style="width:40px;" type="text" size="3" maxlength="3" name="ip4" id="ip1" />
+    <input style="width:40px;" type="text" size="3" maxlength="3" name="ip2" id="ip2" />.
+    <input style="width:40px;" type="text" size="3" maxlength="3" name="ip3" id="ip3" />.
+    <input style="width:40px;" type="text" size="3" maxlength="3" name="ip4" id="ip4" />
 	/ <select name="mask" id="mask" >
      <option value="8">8 {$locale->tr("bits")}</option>
      <option value="16">16 {$locale->tr("bits")}</option>




More information about the pLog-svn mailing list