<commit_before><?php
/**
 * @author <NAME>
 */

namespace Tempeus\Model;

use Nette\Object;
use Tempeus\ApiModule\BaseApiPresenter;

class ApiEntityFactory extends Object
{
	protected $presenter;

	public $maxDepth = 6;

	public function __construct(BaseApiPresenter $presenter)
	{
		$this->presenter = $presenter;
	}

	public function createUsersFromSessions(array $sessions)
	{
		$users = array();
		foreach($sessions as $session) {
			$users[] = $session->user;
		}
		return $this->createUsers($users);
	}

	public function createUsers(array $users)
	{
		$return = array();
		foreach($users as $user) {
			$return[$user->id] = $this->createUser($user);
		}
		return $return;
	}

	public function createUser(User $user)
	{
		return array(
			'id' => $user->id,
			'nick' => $user->nick,
			'links' => array(
				'profile' => $this->presenter->link('//:User:Profile:detail', array('id' => $user->nick)),
				'chat' => $this->presenter->link('//:Api:Chat:privateOpen', array('id' => $user->nick)),
			),
			'roles' => $this->createRoles($user->roles),
		);
	}

	public function createRoles(array $roles)
	{
		$return = array();
		foreach($roles as $role) {
			$return[] = $this->createRole($role);
		}
		return $return;
	}

	public function createRole(Role $role)
	{
		return array(
			'id' => $role->id,
			'name' => $role->name,
			'label' => $role->displayLabel ? NULL : array(
				'text' => $role->labelText,
				'class' => $role->labelClass,
			),
		);
	}

	public function createRooms(array $rooms)
	{
		$return = array();
		foreach($rooms as $room) {
			$return[$room->id] = $this->createRoom($room);
		}
		return $return;
	}

	public function createRoom(ChatRoom $room)
	{
		return array(
			'id' => $room->id,
			'name' => $room->name,
			'public' => $room->public,
			'links' => array(
			)
		);
	}

	public function createMessages(array $messages)
	{
		$return = array();
		foreach($messages as $message) {
			$return[$message->id] = $this->createMessage($message);
		}
		return $return;
	}

	public function createMessage(ChatMessage $message)
	{
		return array(
			'id' => $message->id,
			'message' => $message->message,
			'user' => $message->user->id,
			'time' => $message->time * 1000,
		);
	}
}<commit_msg>Fixed chat allowing HTML<commit_after><?php
/**
 * @author <NAME>
 */

namespace Tempeus\Model;

use Nette\Object;
use Tempeus\ApiModule\BaseApiPresenter;
use Latte\Runtime\Filters;

class ApiEntityFactory extends Object
{
	protected $presenter;

	public $maxDepth = 6;

	public function __construct(BaseApiPresenter $presenter)
	{
		$this->presenter = $presenter;
	}

	public function createUsersFromSessions(array $sessions)
	{
		$users = array();
		foreach($sessions as $session) {
			$users[] = $session->user;
		}
		return $this->createUsers($users);
	}

	public function createUsers(array $users)
	{
		$return = array();
		foreach($users as $user) {
			$return[$user->id] = $this->createUser($user);
		}
		return $return;
	}

	public function createUser(User $user)
	{
		return array(
			'id' => $user->id,
			'nick' => $user->nick,
			'links' => array(
				'profile' => $this->presenter->link('//:User:Profile:detail', array('id' => $user->nick)),
				'chat' => $this->presenter->link('//:Api:Chat:privateOpen', array('id' => $user->nick)),
			),
			'roles' => $this->createRoles($user->roles),
		);
	}

	public function createRoles(array $roles)
	{
		$return = array();
		foreach($roles as $role) {
			$return[] = $this->createRole($role);
		}
		return $return;
	}

	public function createRole(Role $role)
	{
		return array(
			'id' => $role->id,
			'name' => $role->name,
			'label' => $role->displayLabel ? NULL : array(
				'text' => $role->labelText,
				'class' => $role->labelClass,
			),
		);
	}

	public function createRooms(array $rooms)
	{
		$return = array();
		foreach($rooms as $room) {
			$return[$room->id] = $this->createRoom($room);
		}
		return $return;
	}

	public function createRoom(ChatRoom $room)
	{
		return array(
			'id' => $room->id,
			'name' => $room->name,
			'public' => $room->public,
			'links' => array(
			)
		);
	}

	public function createMessages(array $messages)
	{
		$return = array();
		foreach($messages as $message) {
			$return[$message->id] = $this->createMessage($message);
		}
		return $return;
	}

	public function createMessage(ChatMessage $message)
	{
		return array(
			'id' => $message->id,
			'message' => Filters::escapeHtml($message->message),
			'user' => $message->user->id,
			'time' => $message->time * 1000,
		);
	}
}
{'fraction_non_alphanumeric': 0.19228210246174318, 'fraction_numerical': 0.0022177866489243737, 'mean_word_length': 3.7674418604651163, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 113, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4014754', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1613, 'n_words': 321}