public function bind($array, $ignore = '', $prefix = null) { global $_CB_framework; $bind = parent::bind($array, $ignore, $prefix); if ($bind) { $plugin = cbblogsClass::getPlugin(); $myId = $_CB_framework->myId(); $isModerator = Application::MyUser()->isGlobalModerator(); $this->set('created_by', (int) Get::get($array, 'user', $this->get('created_by', $myId)), GetterInterface::INT); $this->set('title', Get::get($array, 'title', $this->get('title')), GetterInterface::STRING); $this->set('introtext', Get::get($array, 'blog_intro', $this->get('introtext'), GetterInterface::HTML)); $this->set('fulltext', Get::get($array, 'blog_full', $this->get('fulltext'), GetterInterface::HTML)); if ($plugin->params->get('blog_category_config', 1) || $isModerator) { $this->set('catid', (int) Get::get($array, 'category', $this->get('catid', $plugin->params->get('blog_k2_category_default', null)), GetterInterface::INT)); } else { $this->set('catid', (int) $this->get('catid', $plugin->params->get('blog_k2_category_default', null))); } if (!$plugin->params->get('blog_approval', 0) && $plugin->params->get('blog_published_config', 1) || $isModerator) { $this->set('published', (int) Get::get($array, 'published', $this->get('published', $plugin->params->get('blog_published_default', 1)), GetterInterface::INT)); } else { $this->set('published', (int) $this->get('published', $plugin->params->get('blog_approval', 0) ? 0 : $plugin->params->get('blog_published_default', 1))); } if ($plugin->params->get('blog_access_config', 1) || $isModerator) { $this->set('access', (int) Get::get($array, 'access', $this->get('access', $plugin->params->get('blog_access_default', 1)), GetterInterface::INT)); } else { $this->set('access', (int) $this->get('access', $plugin->params->get('blog_access_default', 1))); } $this->set('ordering', (int) $this->get('ordering', 1)); $this->map(); } return $bind; }
/** * Gets a clean param value * * @param string|string[] $key Name of index or array of names of indexes, each with name or input-name-encoded array selection, e.g. a.b.c * @param mixed|GetterInterface $default [optional] Default value, or, if instanceof GetterInterface, parent GetterInterface for the default value * @param string|array $type [optional] default: null: raw. Or const int GetterInterface::COMMAND|GetterInterface::INT|... or array( const ) or array( $key => const ) * @return string|array * * @throws \InvalidArgumentException If namespace doesn't exist */ public function get($key, $default = null, $type = null) { if (is_array($key)) { $va = array(); foreach ($key as $k) { $va[$k] = $this->get($k, is_array($default) ? $default[$k] : $default, is_array($type) ? $type[$k] : $type); } return $va; } // Check for namespaced get( 'namespace/key' ): if (strpos($key, '/') !== false) { list($namespace, $subKey) = explode('/', $key, 2); return $this->getNamespaceRegistry($namespace)->get($subKey, $default, $type); } // Check in parent if not existing: if ($this->parent && !$this->hasInThis($key)) { return $this->parent->get($key, $default, $type); } // Get value in this Parameters: return Get::get($this->params, $key, $default, $type === null ? $this->defaultGetType : $type, $this->srcGpc); }
public function bind( $array, $ignore = '', $prefix = null ) { global $_CB_framework; $bind = parent::bind( $array, $ignore, $prefix ); if ( $bind ) { $plugin = cbconsultationsClass::getPlugin(); $myId = $_CB_framework->myId(); $isModerator = Application::MyUser()->isGlobalModerator(); $this->set( 'user', (int) Get::get( $array, 'user', $this->get( 'user', $myId ), GetterInterface::INT ) ); $this->set( 'title', Get::get( $array, 'title', $this->get( 'title' ), GetterInterface::STRING ) ); $this->set( 'consultation_intro', Get::get( $array, 'consultation_intro', $this->get( 'consultation_intro' ), GetterInterface::HTML ) ); $this->set( 'consultation_full', Get::get( $array, 'consultation_full', $this->get( 'consultation_full' ), GetterInterface::HTML ) ); $this->set( 'category', ( ( $plugin->params->get( 'consultation_category_config', 1 ) || $isModerator ) ? Get::get( $array, 'category', $this->get( 'category' ), GetterInterface::STRING ) : $this->get( 'category', $plugin->params->get( 'consultation_int_category_default', 'General' ) ) ) ); $this->set( 'published', (int) ( ( ( ! $plugin->params->get( 'consultation_approval', 0 ) ) || $isModerator ) ? Get::get( $array, 'published', $this->get( 'published' ), GetterInterface::INT ) : $this->get( 'published', $plugin->params->get( 'consultation_approval', 0 ) ) ) ); $this->set( 'access', (int) ( ( $plugin->params->get( 'consultation_access_config', 1 ) || $isModerator ) ? Get::get( $array, 'access', $this->get( 'access' ), GetterInterface::INT ) : $this->get( 'access', $plugin->params->get( 'consultation_access_default', 1 ) ) ) ); $this->set( 'ordering', (int) $this->get( 'ordering', 1 ) ); } return $bind; }
/** * Valiadtes a captcha code * * @param null|string $code * @param bool $reset * @return bool */ public function validateCaptcha( $code = null, $reset = true ) { global $_CB_framework, $_CB_database; if ( ! $code ) { $code = $this->getCaptchaInputValue(); } $valid = false; $ipAddresses = cbGetIParray(); $ipAddress = trim( array_shift( $ipAddresses ) ); if ( $code ) switch( $this->mode ) { case 'recaptcha': $client = new GuzzleHttp\Client(); try { $body = array( 'secret' => $this->params->get( 'captcha_recaptcha_secret_key', null ), 'remoteip' => $ipAddress, 'response' => $code ); $result = $client->get( 'https://www.google.com/recaptcha/api/siteverify', array( 'query' => $body ) ); if ( $result->getStatusCode() == 200 ) { $response = $result->json(); if ( isset( $response['success'] ) && ( $response['success'] == true ) ) { $valid = true; } } } catch ( Exception $e ) {} break; case 'question': $captchaQuestions = "What is 2 plus 2?=4\n" . "What is 1 times 6?=6\n" . "What is 9 divide 3?=3\n" . "Are you a Human?=Yes\n" . "Are you a Bot?=No\n" . "How many words is this?=5\n" . "How many fingers on a hand?=5\n" . "How many toes on a foot?=5\n" . "What is 10 add 10?=20\n" . "What is 0 multiply 100?=0\n" . "What is 5 minus 1?=4\n" . "What is 2 add 2?=4\n" . "4th letter of Test is?=t\n" . "20, 81, 3; which is smallest?=3\n" . "12, 31, 9; which is greatest?=31\n" . "Purple, car, dog; which is a color?=Purple\n" . "Cat, plane, rock; which is an animal?=Cat\n" . "If tomorrow is Monday; what day is today?=Sunday\n" . "Tim, cat, dog; which is human?=Tim"; $questions = $this->params->get( 'captcha_internal_questions', $captchaQuestions ); if ( ! $questions ) { $questions = $captchaQuestions; } $questions = explode( "\n", $questions ); $codes = array(); foreach ( $questions as $question ) { $question = explode( '=', $question ); $key = ( isset( $question[0] ) ? trim( CBTxt::T( $question[0] ) ) : null ); $value = ( isset( $question[1] ) ? trim( CBTxt::T( $question[1] ) ) : null ); if ( $key && $value ) { $codes[$key] = $value; } } $captchaCode = $this->getCaptchaCode(); if ( $captchaCode && isset( $codes[$captchaCode] ) && ( strtolower( $codes[$captchaCode] ) == strtolower( $code ) ) ) { $valid = true; } break; case 'internal': default: $captchaCode = $this->getCaptchaCode(); if ( $captchaCode && ( $captchaCode == $code ) ) { $valid = true; } break; } if ( $valid && $reset ) { $this->setSession( null ); } if ( $this->params->get( 'captcha_honeypot', 1 ) ) { $honeyPot = $this->params->get( 'captcha_honeypot_name', 'full_address' ); if ( ! $honeyPot ) { $honeyPot = 'full_address'; } if ( Get::get( $_REQUEST, $honeyPot, null, GetterInterface::STRING ) ) { $valid = false; } } if ( $reset ) { $blocked = cbantispamClass::getUserBlock( null, $ipAddress ); $message = $this->params->get( 'captcha_autoblock_msg', 'Your captcha attempt has been blocked. Reason: [reason]' ); if ( $blocked ) { if ( $message ) { $extras = array( '[duration]' => ucwords( strtolower( str_replace( array( '+', '-' ), '', $blocked->get( 'duration' ) ) ) ), '[date]' => $blocked->get( 'date' ) . ' UTC', '[expire]' => $blocked->getExpire() . ( $blocked->get( 'duration' ) ? ' UTC' : null ) ); $extras = array_merge( $extras, array( '[reason]' => CBTxt::T( 'CAPTCHA_BLOCK_REASON', ( $blocked->get( 'reason' ) ? $blocked->get( 'reason' ) : 'Spam.' ), $extras ) ) ); $this->error = CBTxt::T( 'CAPTCHA_BLOCK_MESSAGE', $message, $extras ); } $valid = false; } elseif ( $this->params->get( 'general_attempts', 1 ) ) { if ( ! $valid ) { $timeframe = $this->params->get( 'captcha_autoblock_timeframe', '-1 DAY' ); $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_attempts' ) . "\n WHERE " . $_CB_database->NameQuote( 'ip_address' ) . " = " . $_CB_database->Quote( $ipAddress ) . "\n AND " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( 'captcha' ) . "\n ORDER BY " . $_CB_database->NameQuote( 'date' ) . " DESC"; $_CB_database->setQuery( $query, 0, 1 ); $attempt = new cbantispamAttemptsTable(); $_CB_database->loadObject( $attempt ); if ( ! $attempt->get( 'id' ) ) { $attempt->set( 'ip_address', $ipAddress ); $attempt->set( 'type', 'captcha' ); $attempt->set( 'count', 1 ); } elseif ( ( ! $timeframe ) || ( $_CB_framework->getUTCTimestamp( $attempt->get( 'date' ) ) >= $_CB_framework->getUTCTimestamp( strtolower( $timeframe ) ) ) ) { $attempt->set( 'count', ( (int) $attempt->get( 'count' ) + 1 ) ); } $attempt->set( 'date', $_CB_framework->getUTCDate() ); $attempt->store(); if ( $this->params->get( 'captcha_autoblock', 1 ) && cbantispamClass::isUserBlockable( null, $ipAddress ) ) { $count = (int) $this->params->get( 'captcha_autoblock_count', 20 ); if ( ! $count ) { $count = 20; } if ( (int) $attempt->get( 'count' ) >= $count ) { $reason = $this->params->get( 'captcha_autoblock_reason', 'Too many failed captcha attempts.' ); if ( $this->params->get( 'captcha_autoblock_method', 0 ) ) { $row = new cbantispamBlockTable(); $row->set( 'type', 'ip' ); $row->set( 'value', $ipAddress ); $row->set( 'date', $_CB_framework->getUTCDate() ); $row->set( 'duration', $this->params->get( 'captcha_autoblock_dur', '+1 HOUR' ) ); $row->set( 'reason', $reason ); $row->store(); if ( $message ) { $extras = array( '[duration]' => ucwords( strtolower( str_replace( array( '+', '-' ), '', $row->get( 'duration' ) ) ) ), '[date]' => $row->get( 'date' ) . ' UTC', '[expire]' => $row->getExpire() . ( $row->get( 'duration' ) ? ' UTC' : null ) ); $extras = array_merge( $extras, array( '[reason]' => CBTxt::T( 'CAPTCHA_BLOCK_REASON', ( $row->get( 'reason' ) ? $row->get( 'reason' ) : 'Spam.' ), $extras ) ) ); $this->error = CBTxt::T( 'CAPTCHA_BLOCK_MESSAGE', $message, $extras ); } } elseif ( $message ) { $extras = array( '[duration]' => null, '[date]' => null, '[expire]' => null ); $extras = array_merge( $extras, array( '[reason]' => CBTxt::T( 'CAPTCHA_BLOCK_REASON', ( $reason ? $reason : 'Spam.' ), $extras ) ) ); $this->error = CBTxt::T( 'CAPTCHA_BLOCK_MESSAGE', $message, $extras ); } } } } else { $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_antispam_attempts' ) . "\n WHERE " . $_CB_database->NameQuote( 'ip_address' ) . " = " . $_CB_database->Quote( $ipAddress ) . "\n AND " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( 'captcha' ) . "\n ORDER BY " . $_CB_database->NameQuote( 'date' ) . " DESC"; $_CB_database->setQuery( $query ); $attempts = $_CB_database->loadObjectList( null, 'cbantispamAttemptsTable', array( $_CB_database ) ); /** @var cbantispamAttemptsTable[] $attempts */ foreach ( $attempts as $attempt ) { $attempt->delete(); } } } } return $valid; }
public function bind( $array, $ignore = '', $prefix = null ) { global $_CB_framework; $bind = parent::bind( $array, $ignore, $prefix ); if ( $bind ) { $plugin = cbhangoutClass::getPlugin(); $myId = $_CB_framework->myId(); $isModerator = Application::MyUser()->isGlobalModerator(); $this->set( 'created_by', (int) Get::get( $array, 'user', $this->get( 'created_by', $myId ) ), GetterInterface::INT ); $this->set( 'title', Get::get( $array, 'title', $this->get( 'title' ), GetterInterface::STRING ) ); $this->set( 'introtext', Get::get( $array, 'hangout_intro', $this->get( 'introtext' ), GetterInterface::HTML ) ); $this->set( 'fulltext', Get::get( $array, 'hangout_full', $this->get( 'fulltext' ), GetterInterface::HTML ) ); $this->set( 'catid', (int) ( ( $plugin->params->get( 'hangout_category_config', 1 ) || $isModerator ) ? Get::get( $array, 'category', $this->get( 'catid' ), GetterInterface::INT ) : $this->get( 'catid', $plugin->params->get( 'hangout_j_category_default', null ) ) ) ); $this->set( 'state', (int) ( ( ( ! $plugin->params->get( 'hangout_approval', 0 ) ) || $isModerator ) ? Get::get( $array, 'published', $this->get( 'state' ), GetterInterface::INT ) : $this->get( 'state', ( $isModerator || ( ! $plugin->params->get( 'hangout_approval', 0 ) ) ? 1 : 0 ) ) ) ); $this->set( 'access', (int) ( ( $plugin->params->get( 'hangout_access_config', 1 ) || $isModerator ) ? Get::get( $array, 'access', $this->get( 'access' ), GetterInterface::INT ) : $this->get( 'access', $plugin->params->get( 'hangout_access_default', 1 ) ) ) ); $this->set( 'ordering', (int) $this->get( 'ordering', 1 ) ); $this->map(); } return $bind; }