<commit_before><?php

/**
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * This software is a derived product, based on:
 *
 * Simple Machines Forum (SMF)
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
 * license:  	BSD, See included LICENSE.TXT for terms and conditions.
 *
 * @version 1.0 Alpha
 *
 */

if (!defined('ELK'))
	die('No access...');

/**
 * Validates, if a smiley already exists
 *
 * @param array $smileys
 * @return array
 */
function smileyExists($smileys)
{
	$db = database();

	$found = array();
	$request = $db->query('', '
		SELECT filename
		FROM {db_prefix}smileys
		WHERE filename IN ({array_string:smiley_list})',
		array(
			'smiley_list' => $smileys,
		)
	);
	while ($row = $db->fetch_assoc($request))
		$found[] = $row['filename'];
	$db->free_result($request);

	return $found;
}

/**
 * Validates duplicate smileys
 *
 * @param string $code
 * @param string $current
 * @return boolean
 */
function validateDuplicateSmiley($code, $current = null)
{
	$db = database();

	$db = database();

	$request = $db->query('', '
		SELECT id_smiley
		FROM {db_prefix}smileys
		WHERE code = {raw:mysql_binary_type} {string:smiley_code}' . (!isset($current) ? '' : '
			AND id_smiley != {int:current_smiley}'),
		array(
			'current_smiley' => $current,
			'mysql_binary_type' => $db->db_title() == 'MySQL' ? 'BINARY' : '',
			'smiley_code' => $code,
		)
	);
	if ($db->num_rows($request) > 0)
		return true;
	$db->free_result($request);

	return false;
}

/**
 * Request the next location for a new smiley
 *
 * @param type $location
 * @return type
 */
function nextSmileyLocation($location)
{
	$db = database();

	$request = $db->query('', '
		SELECT MAX(smiley_order) + 1
		FROM {db_prefix}smileys
		WHERE hidden = {int:smiley_location}
			AND smiley_row = {int:first_row}',
		array(
			'smiley_location' => $location,
			'first_row' => 0,
		)
	);
	list ($smiley_order) = $db->fetch_row($request);
	$db->free_result($request);

	return $smiley_order;
}

/**
 * Adds a smiley to the database
 *
 * @param array $param
 */
function addSmiley($param)
{
	$db = database();

	$db->insert('',
		'{db_prefix}smileys',
		array(
			'code' => 'string-30', 'filename' => 'string-48', 'description' => 'string-80', 'hidden' => 'int', 'smiley_order' => 'int',
		),
		$param,
		array('id_smiley')
	);
}

/**
 * Deletes smileys.
 *
 * @param array $smileys
 */
function deleteSmileys($smileys)
{
	$db = database();

	$db->query('', '
		DELETE FROM {db_prefix}smileys
		WHERE id_smiley IN ({array_int:checked_smileys})',
		array(
			'checked_smileys' => $smileys,
		)
	);
}

/**
 * Changes the display type of given smileys.
 *
 * @param array $smileys
 * @param int $display_type
 */
function updateSmileyDisplayType($smileys, $display_type)
{
	$db = database();

	$db->query('', '
		UPDATE {db_prefix}smileys
		SET hidden = {int:display_type}
		WHERE id_smiley IN ({array_int:checked_smileys})',
		array(
			'checked_smileys' => $smileys,
			'display_type' => $display_type,
		)
	);
}

/**
 * Updates a smiley..
 *
 * @param array $param
 */
function updateSmiley($param)
{
	$db = database();

	$db->query('', '
		UPDATE {db_prefix}smileys
		SET
			code = {string:smiley_code},
			filename = {string:smiley_filename},
			description = {string:smiley_description},
			hidden = {int:smiley_location}
		WHERE id_smiley = {int:current_smiley}',
		array(
			'smiley_location' => $param['smiley_location'],
			'current_smiley' => $param['smiley'],
			'smiley_code' => $param['smiley_code'],
			'smiley_filename' => $param['smiley_filename'],
			'smiley_description' => $param['smiley_description'],
		)
	);
}

/**
 * Get detailed smiley information
 *
 * @param int $id
 * @return array
 */
function getSmiley($id)
{
	$db = database();

	$request = $db->query('', '
		SELECT id_smiley AS id, code, filename, description, hidden AS location, 0 AS is_new
		FROM {db_prefix}smileys
		WHERE id_smiley = {int:current_smiley}',
		array(
			'current_smiley' => $id,
		)
	);
	if ($db->num_rows($request) != 1)
		fatal_lang_error('smiley_not_found');
	$current_smiley = $db->fetch_assoc($request);
	$db->free_result($request);

	return $current_smiley;
}

/**
 * Get the position from a given smiley
 *
 * @param int $location
 * @param int $id
 * @return array
 */
function getSmileyPosition($location, $id)
{<commit_msg>! Update getSmiley to also return the row the smiley is in<commit_after><?php

/**
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * This software is a derived product, based on:
 *
 * Simple Machines Forum (SMF)
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
 * license:  	BSD, See included LICENSE.TXT for terms and conditions.
 *
 * @version 1.0 Alpha
 *
 */

if (!defined('ELK'))
	die('No access...');

/**
 * Validates, if a smiley already exists
 *
 * @param array $smileys
 * @return array
 */
function smileyExists($smileys)
{
	$db = database();

	$found = array();
	$request = $db->query('', '
		SELECT filename
		FROM {db_prefix}smileys
		WHERE filename IN ({array_string:smiley_list})',
		array(
			'smiley_list' => $smileys,
		)
	);
	while ($row = $db->fetch_assoc($request))
		$found[] = $row['filename'];
	$db->free_result($request);

	return $found;
}

/**
 * Validates duplicate smileys
 *
 * @param string $code
 * @param string $current
 * @return boolean
 */
function validateDuplicateSmiley($code, $current = null)
{
	$db = database();

	$db = database();

	$request = $db->query('', '
		SELECT id_smiley
		FROM {db_prefix}smileys
		WHERE code = {raw:mysql_binary_type} {string:smiley_code}' . (!isset($current) ? '' : '
			AND id_smiley != {int:current_smiley}'),
		array(
			'current_smiley' => $current,
			'mysql_binary_type' => $db->db_title() == 'MySQL' ? 'BINARY' : '',
			'smiley_code' => $code,
		)
	);
	if ($db->num_rows($request) > 0)
		return true;
	$db->free_result($request);

	return false;
}

/**
 * Request the next location for a new smiley
 *
 * @param type $location
 * @return type
 */
function nextSmileyLocation($location)
{
	$db = database();

	$request = $db->query('', '
		SELECT MAX(smiley_order) + 1
		FROM {db_prefix}smileys
		WHERE hidden = {int:smiley_location}
			AND smiley_row = {int:first_row}',
		array(
			'smiley_location' => $location,
			'first_row' => 0,
		)
	);
	list ($smiley_order) = $db->fetch_row($request);
	$db->free_result($request);

	return $smiley_order;
}

/**
 * Adds a smiley to the database
 *
 * @param array $param
 */
function addSmiley($param)
{
	$db = database();

	$db->insert('',
		'{db_prefix}smileys',
		array(
			'code' => 'string-30', 'filename' => 'string-48', 'description' => 'string-80', 'hidden' => 'int', 'smiley_order' => 'int',
		),
		$param,
		array('id_smiley')
	);
}

/**
 * Deletes smileys.
 *
 * @param array $smileys
 */
function deleteSmileys($smileys)
{
	$db = database();

	$db->query('', '
		DELETE FROM {db_prefix}smileys
		WHERE id_smiley IN ({array_int:checked_smileys})',
		array(
			'checked_smileys' => $smileys,
		)
	);
}

/**
 * Changes the display type of given smileys.
 *
 * @param array $smileys
 * @param int $display_type
 */
function updateSmileyDisplayType($smileys, $display_type)
{
	$db = database();

	$db->query('', '
		UPDATE {db_prefix}smileys
		SET hidden = {int:display_type}
		WHERE id_smiley IN ({array_int:checked_smileys})',
		array(
			'checked_smileys' => $smileys,
			'display_type' => $display_type,
		)
	);
}

/**
 * Updates a smiley.
 *
 * @param array $param
 */
function updateSmiley($param)
{
	$db = database();

	$db->query('', '
		UPDATE {db_prefix}smileys
		SET
			code = {string:smiley_code},
			filename = {string:smiley_filename},
			description = {string:smiley_description},
			hidden = {int:smiley_location}
		WHERE id_smiley = {int:current_smiley}',
		array(
			'smiley_location' => $param['smiley_location'],
			'current_smiley' => $param['smiley'],
			'smiley_code' => $param['smiley_code'],
			'smiley_filename' => $param['smiley_filename'],
			'smiley_description' => $param['smiley_description'],
		)
	);
}

/**
 * Get detailed smiley information
 *
 * @param int $id
 * @return array
 */
function getSmiley($id)
{
	$db = database();

	$request = $db->query('', '
		SELECT id_smiley AS id, code, filename, description, hidden AS location, 0 AS is_new, smiley_row AS row
		FROM {db_prefix}smileys
		WHERE id_smiley = {int:current_smiley}',
		array(
			'current_smiley' => $id,
		)
	);
	if ($db->num_rows($request) != 1)
		fatal_lang_error('smiley_not_found');
	$current_smiley = $db->fetch_assoc($request);
	$db->free_result($request);

	return $current_smiley;
}

/**
 * Get the position from a given smiley
 *
 * @param int $location
 * @param int $id
 * @return array
 */
function getSmileyPosition($location, $id)
{
{'fraction_non_alphanumeric': 0.17357600269632625, 'fraction_numerical': 0.004044489383215369, 'mean_word_length': 4.110218140068886, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3371076', 'n_tokens_mistral': 3498, 'n_tokens_neox': 3249, 'n_words': 720}