Documentation

Like
in package
implements ActionInterface

Handles liking posts and displaying the list of who liked a post.

Table of Contents

Interfaces

ActionInterface
Interface for all action classes.

Properties

$subaction  : string
$subactions  : array<string|int, mixed>
$already_liked  : bool
$content  : int
$data  : mixed
$error  : string
$extra  : string
$id_topic  : int
$js  : bool
$num_likes  : int
$obj  : object
$set_response  : bool
$type  : string
$valid_likes  : array<string|int, mixed>

Methods

BookOfUnknown()  : mixed
What's this? I dunno, what are you talking about? Never seen this before, nope. No sir.
call()  : void
Convenience method to load() and execute() an instance of this class.
execute()  : void
The main handler.
get()  : mixed
A simple getter for all protected properties.
load()  : An
Wrapper for constructor. Ensures only one instance is created.
__construct()  : mixed
Sets the basic data needed for the rest of the process.
check()  : void
Performs basic checks on the data provided, checks for a valid msg like.
count()  : void
Sets $this->num_likes to the actual number of likes that the content has.
delete()  : void
Deletes an entry from user_likes table.
insert()  : void
Inserts a new entry on user_likes table.
like()  : void
Performs a like action, either like or unlike.
respond()  : void
Checks if the user can use JavaScript and acts accordingly.
sendJsonReponse()  : void
Outputs a JSON-encoded response.
view()  : void
This is for viewing the people who liked a thing.

Properties

$subaction

public string $subaction = 'like'

The requested sub-action. This should be set by the constructor.

$subactions

public static array<string|int, mixed> $subactions = ['like' => 'like', 'view' => 'view', 'delete' => 'delete', 'insert' => 'insert', 'count' => 'count']

Available sub-actions.

Tags
todo

Do delete, insert, and count really need to be sub-actions? They are never used as sub-actions in practice. Instead, they are only ever called internally by the like() method. Moreover, the control flow regarding hooks, etc., assumes that they are only called by like().

$already_liked

protected bool $already_liked = false

If the current user has already liked this content.

$content

protected int $content = 0

A valid ID to identify the content being liked.

$data

protected mixed $data

Data for the response.

$error

protected string $error = false

If filled, its value will contain a string matching a key on a language var Lang::$txt[$this->error]

$extra

protected string $extra = false

A generic string used if you need to pass any extra info. It gets set via $_GET['extra'].

$id_topic

protected int $id_topic = 0

The topic ID. Used for liking messages.

$js

protected bool $js = false

Know if a request comes from an ajax call or not. Depends on $_GET['js'] been set.

$num_likes

protected int $num_likes = 0

The number of times the content has been liked.

$obj

protected static object $obj

An instance of this class.

$set_response

protected bool $set_response = true

Whether respond() will be executed as normal.

If this is set to false it indicates the method already implemented its own way to send back a response.

$type

protected string $type = ''

The unique type to like, needs to be unique and it needs to be no longer than 6 characters, only numbers and letters are allowed.

$valid_likes

protected array<string|int, mixed> $valid_likes = ['can_like' => false, 'redirect' => '', 'type' => '', 'flush_cache' => '', 'callback' => false, 'json' => false]

Mostly used for external integration. Needs to be filled as an array with the following keys:

'can_like' bool|string True if the current user can actually like this content, or a Lang::$txt key for an error message if not.

'redirect' string URL to redirect to after the like is submitted. If not set, will redirect to the forum index.

'type' string 6 character unique identifier for the content. Must match what was sent in $_GET['ltype']

'flush_cache' bool If true, reset the like content's cache entry after a new entry has been inserted. Optional.

'callback' callable Optional function or method to call immediately after like data has been inserted or deleted. If set, the callback will be called before the integrate_issue_like hook.

'json' bool If true, the class will return a JSON object as a response instead of HTML. Default: false.

Methods

BookOfUnknown()

What's this? I dunno, what are you talking about? Never seen this before, nope. No sir.

public static BookOfUnknown() : mixed

call()

Convenience method to load() and execute() an instance of this class.

public static call() : void

execute()

The main handler.

public execute() : void

Verifies permissions (whether the user can see the content in question), dispatch different method for different sub-actions.

Accessed from index.php?action=likes

get()

A simple getter for all protected properties.

public get([string $property = '' ]) : mixed

This is meant to give read-only access to hooked functions.

Parameters
$property : string = ''

The name of the property to get.

Return values
mixed

Either return the property or false if there isn't a property with that name.

load()

Wrapper for constructor. Ensures only one instance is created.

public static load() : An
Return values
An

instance of this class.

__construct()

Sets the basic data needed for the rest of the process.

protected __construct() : mixed

Protected to force instantiation via load().

check()

Performs basic checks on the data provided, checks for a valid msg like.

protected check() : void

Calls integrate_valid_likes hook for retrieving all the data needed and apply checks based on the data provided.

count()

Sets $this->num_likes to the actual number of likes that the content has.

protected count() : void

delete()

Deletes an entry from user_likes table.

protected delete() : void

insert()

Inserts a new entry on user_likes table.

protected insert() : void

Creates a background task for the inserted entry.

like()

Performs a like action, either like or unlike.

protected like() : void

Counts the total of likes and calls a hook after the event.

respond()

Checks if the user can use JavaScript and acts accordingly.

protected respond() : void

Calls the appropriate sub-template for each method Handles error messages.

sendJsonReponse()

Outputs a JSON-encoded response.

protected sendJsonReponse() : void

view()

This is for viewing the people who liked a thing.

protected view() : void

Accessed from index.php?action=likes;view and should generally load in a popup.

We use a template for this in case themers want to style it.


        
On this page

Search results