/**
  * Carries out the specified action
  */
 function perform()
 {
     // fetch the data
     $this->_hostId = $this->_request->getValue("hostId");
     $blockedHosts = new BlockedHosts();
     $blockedHost = $blockedHosts->getBlockedHost($this->_hostId);
     // check if the info about the blocked host is correct
     if (!$blockedHost) {
         $this->_view = new AdminBlockedHostsView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_blocked_host"));
         $this->setCommonData();
         return false;
     }
     // if so, continue
     $this->_view = new AdminEditBlockedHostView($this->_blogInfo, $this->_hostId);
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 function render()
 {
     $blogSettings = $this->_blogInfo->getSettings();
     $pluginEnabled = $blogSettings->getValue("plugin_hostblock_enabled");
     $blockedHosts = new BlockedHosts();
     $blockedHost = $blockedHosts->getBlockedHost($this->_hostId, $this->_blogInfo->getId());
     $this->setValue("pluginEnabled", $pluginEnabled);
     $this->setValue("blockedhost", $blockedHost);
     // to make things easier in the template, let's do the following:
     $ipParts = explode(".", $blockedHost->getHost());
     $this->setValue("ip1", $ipParts[0]);
     $this->setValue("ip2", $ipParts[1]);
     $this->setValue("ip3", $ipParts[2]);
     $this->setValue("ip4", $ipParts[3]);
     if (!$pluginEnabled) {
         $locale = $this->_blogInfo->getLocale();
         $text = $locale->tr("error_hostblock_not_enabled");
         $this->setErrorMessage($text);
     }
     parent::render();
 }
 /**
  * Carries out the specified action
  */
 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->_ip = $this->_ip1 . "." . $this->_ip2 . "." . $this->_ip3 . "." . $this->_ip4;
     $this->_mask = $this->_request->getValue("mask");
     $this->_type = $this->_request->getValue("blockType");
     $this->_reason = $this->_request->getValue("reason");
     $blockedHosts = new BlockedHosts();
     $blockedHost = $blockedHosts->getBlockedHost($this->_hostId, $this->_blogInfo->getId());
     // check if the info about the blocked host is correct
     if (!$blockedHost) {
         $this->_view = new AdminBlogBlockedHostsView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_blocked_host"));
         $this->setCommonData();
         return false;
     }
     // set the new information
     $blockedHost->setHost($this->_ip);
     $blockedHost->setReason($this->_reason);
     $blockedHost->setType($this->_type);
     $blockedHost->setMask($this->_mask);
     $this->notifyEvent(EVENT_PRE_BLOCK_HOST_UPDATE, array("host" => &$blockedHost));
     if (!$blockedHosts->update($blockedHost)) {
         $this->_view = new AdminBlogBlockedHostsView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_blocked_host"));
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_POST_BLOCK_HOST_UPDATE, array("host" => &$blockedHost));
     $this->_view = new AdminBlogBlockedHostsView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->tr("blocked_host_updated_ok"));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     return true;
 }
 function _deleteBlogBlockedHosts()
 {
     $blockedHosts = new BlockedHosts();
     // loop through the array of things to remove
     $errorMessage = "";
     $successMessage = "";
     $numOk = 0;
     foreach ($this->_blockedIds as $blockedId) {
         // get the post
         $blockedHost = $blockedHosts->getBlockedHost($blockedId, $this->_blogInfo->getId());
         $this->notifyEvent(EVENT_PRE_BLOCK_HOST_DELETE, array("host" => &$blockedHost));
         $result = $blockedHosts->remove($blockedId, $this->_blogInfo->getId());
         if (!$result) {
             $errorMessage .= $this->_locale->pr("error_deleting_blocked_host", $blockedHost->getHost()) . "<br/>";
         } else {
             $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));
         }
     }
     $this->_view = new AdminBlogBlockedHostsView($this->_blogInfo);
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     // better to return true if everything fine
     return true;
 }