This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*@var boolean Know if a request comes from an ajax call or not, depends on $_GET['js'] been set.
*@var boolean Know if a request comes from an ajax call or not, depends on $_GET['js'] been set.
*/
protected$_js = false;
/**
*@var string If filled, its value will contain a string matching a key on a language var $txt[$this->_error]
* @var string The sub action sent in $_GET['sa'].
*/
protected$_sa = null;
/**
* @var string If filled, its value will contain a string matching a key on a language var $txt[$this->_error]
*/
protected$_error = false;
/**
*@var string 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.
*@var string 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.
*/
protected$_type = '';
/**
*@var string A generic string used if you need to pass any extra info. It gets set via $_GET['extra'].
*@var string A generic string used if you need to pass any extra info. It gets set via $_GET['extra'].
*/
protected$_extra = false;
/**
*@var integer a valid ID to identify your like content.
*@var integer a valid ID to identify your like content.
*/
protected$_content = 0;
/**
*@var integer The number of times your content has been liked.
*@var integer The number of times your content has been liked.
*/
protected$_numLikes = 0;
/**
*@var boolean If the current user has already liked this content.
*@var boolean If the current user has already liked this content.
*/
protected$_alreadyLiked = false;
/**
* @var array $_validLikes mostly used for external integration, needs to be filled as an array with the following keys:
* => 'can_see' boolean|string whether or not the current user can see the like.
* => 'can_like' boolean|string whether or not the current user can actually like your content.
* for both can_like and can_see: Return a boolean true if the user can, otherwise return a string, the string will be used as key in a regular $txt language error var. The code assumes you already loaded your language file. If no value is returned or the $txt var isn't set, the code will use a generic error message.
* for can_like: Return a boolean true if the user can, otherwise return a string, the string will be used as key in a regular $txt language error var. The code assumes you already loaded your language file. If no value is returned or the $txt var isn't set, the code will use a generic error message.
* => 'redirect' string To add support for non JS users, It is highly encouraged to set a valid URL to redirect the user to, if you don't provide any, the code will redirect the user to the main page. The code only performs a light check to see if the redirect is valid so be extra careful while building it.
* => 'type' string 6 letters or numbers. The unique identifier for your content, the code doesn't check for duplicate entries, if there are 2 or more exact hook calls, the code will take the first registered one so make sure you provide a unique identifier. Must match with what you sent in $_GET['ltype'].
* => 'flush_cache' boolean this is optional, it tells the code to reset your like content's cache entry after a new entry has been inserted.
* => 'callback' callable optional, useful if you don't want to issue a separate hook for updating your data, it is called immediately after the data was inserted or deleted and before the actual hook. Uses call_helper(); so the same format for your function/method can be applied here.
* => 'json' boolean optional defaults to false, if true the Like class will return a json object as response instead of HTML.
*/
protected$_validLikes = array(
'can_see' => false,
'can_like' => false,
'redirect' => '',
'type' => '',
Expand DownExpand Up
@@ -114,8 +120,6 @@ public function __construct()
*
* The main handler. Verifies permissions (whether the user can see the content in question), dispatch different method for different sub-actions.
* Accessed from index.php?action=likes
* @param
* @return
*/
publicfunctioncall()
{
Expand DownExpand Up
@@ -160,13 +164,14 @@ public function call()
*
* A simple getter for all protected properties.
* Accessed from index.php?action=likes
*
* @param string $property The name of the property to get.
* @return mixed either return the property or false if there isn't a property with that name.
* @return mixed Either return the property or false if there isn't a property with that name.
*/
publicfunctionget($property = '')
{
// All properties inside Likes are protected, thus, an underscore is used.
// Modders: This will give you whatever the user offers up in terms of liking, e.g. $this->_type=msg, $this->_content=1
// When you hook this, check $this->_type first. If it is not something your mod worries about, return false.
// Otherwise, fill an array according to the docs for $this->_validLikes. Determine (however you need to) that the user can see and can_like the relevant liked content (and it exists) Remember that users can't like their own content.
// If the user cannot see it, return the appropriate key (can_see) as false. If the user can see it and can like it, you MUST return your type in the 'type' key back.
// If the user can like it, you MUST return your type in the 'type' key back.