<?php

use Mnv\Core\Config;

include('../../includes/overall.inc.php');

$content = request('content', '');

$keyword_count = 20;
$contentArr = array ();
$quotes = array ("\x22", "\x60", "\t", '\n', '\r', "\n", "\r", "\\", ",", ".", "/", "¬", "#", ";", ":", "@", "~", "[", "]", "{", "}", "=", "-", "+", ")", "(", "*", "^", "%", "$", "<", ">", "?", "!", '"');

$content = strip_tags($content);
$content = str_replace($quotes, ' ', $content);
$arr = explode(" ", $content);

foreach ($arr as $word) {
    if (mnvStrlen($word, Config::getValue('charset')) > 4 ) $contentArr[] = $word;
}

$arr = array_count_values( $contentArr );
arsort($arr);

$arr = array_keys($arr);

$total = count($arr);

$offset = 0;

$arr = array_slice($arr, $offset, $keyword_count);
$keywords = implode(", ", $arr);

$result = array('status' => 200, 'keywords' => $arr );

response()->json($result, \Mnv\Http\Response::HTTP_OK, ['Content-Type' => 'application/json;charset=UTF-8', 'Charset' => 'utf-8'])->send();
exit();