<commit_before><?php

/**
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * @version 1.0 Alpha
 *
 */

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

/**
 * This class contains one likable use, which allows members to like a post
 */
class Likes_Controller extends Action_Controller
{
	/**
	 * Default action method, if a specific methods wasn't
	 * directly called already. Simply forwards to likepost.
	 *
	 * @see Action_Controller::action_index()
	 */
	public function action_index()
	{
		// We like you.
		$this->action_likepost();
	}

	/**
	 * Entry point function for likes, permission checks, just makes sure its on
	 */
	public function pre_dispatch()
	{
		global $modSettings;

		// If likes are disabled, we don't go any further
		if (empty($modSettings['likes_enabled']))
			fatal_lang_error('feature_disabled', true);
	}

	/**
	 * Likes a post due to its awesomeness
	 * Permission checks are done in prepare_likes
	 * It redirects back to the referrer afterward.
	 * It is accessed via ?action=like,sa=likepost
	 */
	public function action_likepost()
	{
		global $user_info, $topic, $modSettings;

		$id_liked = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;

		// We like these
		require_once(SUBSDIR . '/Likes.subs.php');
		require_once(SUBSDIR . '/Messages.subs.php');

		// Have to be able to access it to like it
		if ($this->prepare_like() && canAccessMessage($id_liked))
		{
			$liked_message = basicMessageInfo($id_liked, true, true);
			if ($liked_message)
			{
				likePost($user_info['id'], $liked_message, '+');

				if (!empty($modSettings['notifications_enabled']))
				{
					require_once(CONTROLLERDIR . '/Notification.controller.php');
					$notify = new Notification_Controller();
					$notify->setData(array(
						'id_member' => $liked_message['id_member'],
						'type' => 'like',
						'id_msg' => $id_liked,
					));
					$notify->action_add();
				}
			}
		}

		// Back to where we were, in theory
		redirectexit('topic=' . $topic . '.msg' . $id_liked . '#msg' . $id_liked);
	}

	/**
	 * Unlikes a post that you previously liked ... no negatives though, hurts feelings :'(
	 * It redirects back to the referrer afterward.
	 * It is accessed via ?action=like,sa=unlikepost.
	 */
	public function action_unlikepost()
	{
		global $user_info, $topic, $modSettings;

		$id_liked = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;

		// We used to like these
		require_once(SUBSDIR . '/Likes.subs.php');
		require_once(SUBSDIR . '/Messages.subs.php');

		// Have to be able to access it to unlike it now
		if ($this->prepare_like() && canAccessMessage($id_liked))
		{
			$liked_message = basicMessageInfo($id_liked, true, true);
			if ($liked_message)
			{
				likePost($user_info['id'], $liked_message, '-');

				if (!empty($modSettings['notifications_enabled']))
				{
					require_once(CONTROLLERDIR . '/Notification.controller.php');
					$notify = new Notification_Controller();
					$notify->setData(array(
						'uid' => $liked_message['id_member'],
						'type' => 'rlike',
						'msg' => $id_liked,
					));
					$notify->action_add();
				}<commit_msg>! couple comments, hey someone has to make ohloh stop complaining :P<commit_after><?php

/**
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * @version 1.0 Alpha
 *
 */

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

/**
 * This class contains one likable use, which allows members to like a post
 */
class Likes_Controller extends Action_Controller
{
	/**
	 * Default action method, if a specific methods wasn't
	 * directly called already. Simply forwards to likepost.
	 *
	 * @see Action_Controller::action_index()
	 */
	public function action_index()
	{
		// We like you.
		$this->action_likepost();
	}

	/**
	 * Entry point function for likes, permission checks, just makes sure its on
	 */
	public function pre_dispatch()
	{
		global $modSettings;

		// If likes are disabled, we don't go any further
		if (empty($modSettings['likes_enabled']))
			fatal_lang_error('feature_disabled', true);
	}

	/**
	 * Likes a post due to its awesomeness
	 * Permission checks are done in prepare_likes
	 * It redirects back to the referrer afterward.
	 * It is accessed via ?action=like,sa=likepost
	 */
	public function action_likepost()
	{
		global $user_info, $topic, $modSettings;

		$id_liked = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;

		// We like these
		require_once(SUBSDIR . '/Likes.subs.php');
		require_once(SUBSDIR . '/Messages.subs.php');

		// Have to be able to access it to like it
		if ($this->prepare_like() && canAccessMessage($id_liked))
		{
			$liked_message = basicMessageInfo($id_liked, true, true);
			if ($liked_message)
			{
				likePost($user_info['id'], $liked_message, '+');

				// Oh noes, taking the like back, let them know so they can complain
				if (!empty($modSettings['notifications_enabled']))
				{
					require_once(CONTROLLERDIR . '/Notification.controller.php');
					$notify = new Notification_Controller();
					$notify->setData(array(
						'id_member' => $liked_message['id_member'],
						'type' => 'like',
						'id_msg' => $id_liked,
					));
					$notify->action_add();
				}
			}
		}

		// Back to where we were, in theory
		redirectexit('topic=' . $topic . '.msg' . $id_liked . '#msg' . $id_liked);
	}

	/**
	 * Unlikes a post that you previously liked ... no negatives though, hurts feelings :'(
	 * It redirects back to the referrer afterward.
	 * It is accessed via ?action=like,sa=unlikepost.
	 */
	public function action_unlikepost()
	{
		global $user_info, $topic, $modSettings;

		$id_liked = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;

		// We used to like these
		require_once(SUBSDIR . '/Likes.subs.php');
		require_once(SUBSDIR . '/Messages.subs.php');

		// Have to be able to access it to unlike it now
		if ($this->prepare_like() && canAccessMessage($id_liked))
		{
			$liked_message = basicMessageInfo($id_liked, true, true);
			if ($liked_message)
			{
				likePost($user_info['id'], $liked_message, '-');

				// Lets add in a notify to the member that just had their post liked
				if (!empty($modSettings['notifications_enabled']))
				{
					require_once(CONTROLLERDIR . '/Notification.controller.php');
					$notify = new Notification_Controller();
					$notify->setData(array(
						'uid' => $liked_message['id_member'],
						'type' => 'rlike',
						'msg' => $id_liked,
					));
					$notify->action_add();
				}
{'fraction_non_alphanumeric': 0.1480188249582511, 'fraction_numerical': 0.001518141794443601, 'mean_word_length': 3.4846834581347856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '1445857', 'n_tokens_mistral': 2475, 'n_tokens_neox': 2083, 'n_words': 566}