auth = false; if (empty($parameter['table'])) { $parameter['table'] = WBClass::create('WBDatasource_Table', $parameter); } $this->table = $parameter['table']; // set default namespace $this->namespace = self::NAMESPACE_GLOBAL; $config = WBClass::create('WBConfig'); $c = array(); if ($config->load('captcha', true)) { $c = $config->get('mode/auto', array()); } if (isset($c[self::NAMESPACE_GLOBAL])) { $c[self::NAMESPACE_GLOBAL] = array_merge(array('limit' => 10, 'timeout' => 600), $c[self::NAMESPACE_GLOBAL]); } $this->config = $c; } /** * Set Current Authentication Status * * @param bool * @return WBUte_Captcha */ public function setAuth($auth = true) { $this->auth = $auth; return $this; } /** * Set Current Namespace * * @param bool * @return WBUte_Captcha */ public function setNamespace($namespace = null) { if (empty($namespace)) { $namespace = self::NAMESPACE_GLOBAL; } $this->namespace = $namespace; return $this; } /** * Add Request * * @return WBUte_Captcha */ public function addRequest() { $save = array( 'created' => date('Y-m-d H:i:s'), 'namespace' => $this->namespace, 'authenticated' => intval($this->auth) ); $this->table->save(self::TABLE_CAPTCHAREQUEST, '__new', $save); } /** * Setup Cache Dir * */ public function isRequired($mode) { switch (strtolower($mode)) { case 'auto': break; // CAPTCHA is not required case 'none': case '0': return false; break; // default: CAPTCHA is required default: case '1'; return true; break; } if ($this->auth) { return false; } $min = date('Y-m-d H:i:s', time() - $this->config[$this->namespace]['timeout']); $clause = array(); $clause[] = array( 'field' => 'created', 'relation' => 'ge', 'value' => $min ); $clause[] = array( 'field' => 'namespace', 'value' => $this->namespace ); $cnt = $this->table->count(self::TABLE_CAPTCHAREQUEST, null, null, $clause); if ($cnt > $this->config[$this->namespace]['limit']) { return true; } return false; } }