/** * Function that attaches the core javascript to the page. * * This should be called automatically from the hook /core/page/preexecute. */ public static function _AttachCoreJavascript() { if(Core::IsComponentAvailable('User')){ $userid = (\Core\user()->get('id') ? \Core\user()->get('id') : 0); $userauth = \Core\user()->exists() ? 'true' : 'false'; } else{ $userid = 0; $userauth = 'false'; } $ua = \Core\UserAgent::Construct(); $uastring = ''; foreach($ua->asArray() as $k => $v){ if($v === true){ $uastring .= "\t\t\t$k: true,\n"; } elseif($v === false){ $uastring .= "\t\t\t$k: false,\n"; } else{ $uastring .= "\t\t\t$k: \"$v\",\n"; } } $uastring .= "\t\t\tis_mobile: " . ($ua->isMobile() ? 'true' : 'false') . "\n"; $url = htmlentities(\Core\page_request()->uriresolved); if(ConfigHandler::Get('/core/page/url_remove_stop_words')){ $stopwords = json_encode(\Core\get_stop_words()); $removeStopWords = 'true'; } else{ $stopwords = '""'; $removeStopWords = 'false'; } $version = DEVELOPMENT_MODE ? self::GetComponent()->getVersion() : ''; $rootWDIR = ROOT_WDIR; $rootURL = ROOT_URL; $rootURLSSL = ROOT_URL_SSL; $rootURLnoSSL = ROOT_URL_NOSSL; $ssl = SSL ? 'true' : 'false'; $sslMode = SSL_MODE; $script = <<<EOD <script type="text/javascript"> var Core = { Version: "$version", ROOT_WDIR: "$rootWDIR", ROOT_URL: "$rootURL", ROOT_URL_SSL: "$rootURLSSL", ROOT_URL_NOSSL: "$rootURLnoSSL", SSL: $ssl, SSL_MODE: "$sslMode", User: { id: "$userid", authenticated: $userauth }, Url: "$url", Browser: { $uastring }, URLRemoveStopWords: $removeStopWords, StopWords: $stopwords }; </script> EOD; $minified = \ConfigHandler::Get('/core/javascript/minified'); if($minified){ $script = str_replace(["\t", "\n"], ['', ''], $script); } \Core\view()->addScript($script, 'head'); // And the static functions. \Core\view()->addScript('js/core.js', 'foot'); //\Core\view()->addScript('js/core-foot.js', 'foot'); }
/** * Extract all possible keywords from the content along with their current scores. * * @return array */ public function getKeywords() { $s = strtolower($this->content); $s = strip_tags($s); $s = preg_replace('/[^a-z0-9 ]/', '', $s); $stopwords = \Core\get_stop_words(); // Add on a few more custom stop words that don't necessarily belong in upstream. $stopwords[] = 'id'; $stopwords[] = 'like'; $exploded = explode(' ', $s); $nt = []; foreach ($exploded as $i => $w) { if ($w == '') { continue; } if (in_array($w, $stopwords)) { continue; } $nt[] = $w; if (isset($exploded[$i + 1])) { $nt[] = $w . ' ' . $exploded[$i + 1]; } if (isset($exploded[$i + 2])) { $nt[] = $w . ' ' . $exploded[$i + 1] . ' ' . $exploded[$i + 2]; } } $nt = array_unique($nt); sort($nt); $all = Dataset::Init()->select('*')->table('spam_ham_keyword')->execute(); // Convert this to something I can quickly check through. $keywords = []; foreach ($all as $row) { $keywords[$row['keyword']] = $row['score']; } $ret = []; foreach ($nt as $w) { if (isset($keywords[$w])) { $score = $keywords[$w]; } else { $score = 0; } $ret[] = ['keyword' => $w, 'score' => $score]; } return $ret; }