Difference between revisions of "JReviews:Developers Filters"

From JReviews Documentation
Jump to: navigation, search
Line 175: Line 175:
  
 
== Listing Permissions ==
 
== Listing Permissions ==
 +
 +
=== Trusted On Listing Create ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
  
 
   57:    return $this->filteredResponse($trust,'trusted_on_listing_create');
 
   57:    return $this->filteredResponse($trust,'trusted_on_listing_create');
 +
 +
=== Listing Allows Claims ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   85:    return $this->filteredResponse($permission,'listing_allows_claims',$listing);
 
   85:    return $this->filteredResponse($permission,'listing_allows_claims',$listing);
 +
 +
=== Listing Allows Inquiries ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   132:    return $this->filteredResponse($permission,'listing_allows_inquiries',$listing);
 
   132:    return $this->filteredResponse($permission,'listing_allows_inquiries',$listing);
 +
 +
 +
=== Listing Allows Favorites ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   150:    return $this->filteredResponse($permission,'listing_allows_favorites',$listing);
 
   150:    return $this->filteredResponse($permission,'listing_allows_favorites',$listing);
 +
 +
=== Listing Allows User Reviews ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   173:    return $this->filteredResponse($permission,'listing_allows_user_reviews',$listing);
 
   173:    return $this->filteredResponse($permission,'listing_allows_user_reviews',$listing);
 +
 +
=== Listing Allows Editor Reviews ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   191:    return $this->filteredResponse($permission,'listing_allows_editor_reviews',$listing);
 
   191:    return $this->filteredResponse($permission,'listing_allows_editor_reviews',$listing);
 +
 +
=== Listing User Reviews Open ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   207:    return $this->filteredResponse($permission,'listing_user_reviews_opened',$listing);
 
   207:    return $this->filteredResponse($permission,'listing_user_reviews_opened',$listing);
 +
 +
=== Listing Editor Reviews Open ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   223:    return $this->filteredResponse($permission,'listing_editor_reviews_opened',$listing);
 
   223:    return $this->filteredResponse($permission,'listing_editor_reviews_opened',$listing);
 +
 +
=== Can Create Listing ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   251:    $permission = $this->filteredResponse($permission,'can_create_listing',[$listingTypeId]);
 
   251:    $permission = $this->filteredResponse($permission,'can_create_listing',[$listingTypeId]);
 +
 +
=== Can Update Listing ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   278:    return $this->filteredResponse($permission,'can_update_listing',$listing);
 
   278:    return $this->filteredResponse($permission,'can_update_listing',$listing);
 +
 +
=== Can Add Listing Metadata ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   296:    return $this->filteredResponse($permission,'can_add_listing_metadata',$listingType);
 
   296:    return $this->filteredResponse($permission,'can_add_listing_metadata',$listingType);
 +
 +
=== Can User WYSIWYG Editor in Listing ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   312:    return $this->filteredResponse($permission,'can_use_editor_in_listing',[]);
 
   312:    return $this->filteredResponse($permission,'can_use_editor_in_listing',[]);
 +
 +
=== Can Publish Listing ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   334:    return $this->filteredResponse($permission,'can_publish_listing',$listing);
 
   334:    return $this->filteredResponse($permission,'can_publish_listing',$listing);
 +
 +
=== Can Delete Listing ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   356:    return $this->filteredResponse($permission,'can_delete_listing',$listing);
 
   356:    return $this->filteredResponse($permission,'can_delete_listing',$listing);
 +
 +
=== Can Claim Listing ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   374:    return $this->filteredResponse($permission,'can_claim_listing',$listing);
 
   374:    return $this->filteredResponse($permission,'can_claim_listing',$listing);
 +
 
 +
=== Can Send Listing Inquiry ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   390:    return $this->filteredResponse($permission,'can_send_listing_inquiry',$listing);
 
   390:    return $this->filteredResponse($permission,'can_send_listing_inquiry',$listing);
 +
 
 +
=== Can Favorite Listing ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   406:    return $this->filteredResponse($permission,'can_favorite_listing',$listing);
 
   406:    return $this->filteredResponse($permission,'can_favorite_listing',$listing);
 +
 
 +
=== Can Feature Listing ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   420:    return $this->filteredResponse($permission,'can_feature_listing',[]);
 
   420:    return $this->filteredResponse($permission,'can_feature_listing',[]);
 +
 +
=== Can Create User Review For Listing ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   496:    return $this->filteredResponse($permission,'can_create_user_review_for_listing',$listing,$this->getMessage());
 
   496:    return $this->filteredResponse($permission,'can_create_user_review_for_listing',$listing,$this->getMessage());
 +
 +
=== Can Create Editor Review For Listing ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   546:    return $this->filteredResponse($permission,'can_create_editor_review_for_listing',$listing,$this->getMessage());
 
   546:    return $this->filteredResponse($permission,'can_create_editor_review_for_listing',$listing,$this->getMessage());
 +
 +
=== Can Add Review on Listing Create ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   564:    return $this->filteredResponse($permission,'can_add_review_on_listing_create',$listingType);
 
   564:    return $this->filteredResponse($permission,'can_add_review_on_listing_create',$listingType);
 +
 +
=== Can Update Listing Media ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   586:    return $this->filteredResponse($permission,'can_update_listing_media',[$listing,$listingType]);
 
   586:    return $this->filteredResponse($permission,'can_update_listing_media',[$listing,$listingType]);
 +
 +
=== Can Upload Listing Media ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   624:    return $this->filteredResponse($permission,'can_upload_listing_media',[$listing,$listingType]);
 
   624:    return $this->filteredResponse($permission,'can_upload_listing_media',[$listing,$listingType]);
 +
 +
=== Can Upload Listing Media From URL ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   644:    return $this->filteredResponse($permission,'can_upload_media_from_url_in_listing',$listing);
 
   644:    return $this->filteredResponse($permission,'can_upload_media_from_url_in_listing',$listing);
 +
 +
=== Can Upload Listing Photo ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   662:    return $this->filteredResponse($permission,'can_upload_listing_photo',[$listing,$listingType]);
 
   662:    return $this->filteredResponse($permission,'can_upload_listing_photo',[$listing,$listingType]);
 +
 +
=== Can Upload Listing Video ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   680:    return $this->filteredResponse($permission,'can_upload_listing_video');
 
   680:    return $this->filteredResponse($permission,'can_upload_listing_video');
 +
 +
=== Can Upload Listing Audio ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   698:    return $this->filteredResponse($permission,'can_upload_listing_audio',[$listing,$listingType]);
 
   698:    return $this->filteredResponse($permission,'can_upload_listing_audio',[$listing,$listingType]);
 +
 +
=== Can Upload Listing Attachment ===
 +
 +
==== Description ====
 +
 +
==== Usage ====
 +
 
   716:    return $this->filteredResponse($permission,'can_upload_listing_attachment',[$listing,$listingType]);
 
   716:    return $this->filteredResponse($permission,'can_upload_listing_attachment',[$listing,$listingType]);
  

Revision as of 12:52, 14 February 2018

JReviews 3 comes with Filters that allow you to make certain types of customizations and extend the functionality of JReviews without having to modify core files.

Contents


What is a Filter?

JReviews has many filter hooks strategically placed in the code at points where you may want to change or override the value of a variable at runtime.

Filters can modify data by binding a callback function to a filter hook. When the filter is executed, each callback function is run in order of priority, and can modify the filtered data by returning a new value.

For example, you can use a filter to:

  • Change the page title and metatags of different pages
  • Override the permissions of specific users or user groups for different events (creating listings, reviews, etc.)
  • Add or remove CSS and Scripts to and from the page.

Defining a new Filter Hook

JReviews 3 already comes with many filter hooks and we'll add more over time. However, if you need to create a new filter that is not yet available you would use the following syntax:

$data = \Clickfwd\Hook\Filter::filter('example_filter_name', $data, ['foo'=>$bar]);

Where:

  • $data is the variable that can be modified by filter callback function
  • $params are other arguments that can be passed to the filter callback function to provide context and their values cannot be modified by the filter.

Using Filter Functions

The following example shows how a callback function is bound to a filter hook:

function example_filter_callback_function($data, $params = [])
{
   // Modify $data in some way and return it
   return $data;
}
 
Clickfwd\Hook\Filter::add('example_filter_name', 'example_filter_callback_function', $priority = 10);

The $data variable can be modified inside the callback function and must always be returned at the end of the function.

To create new filter functions that are not overwritten on upgrades, create a new file in overrides and place your filter functions there:

Joomla

/templates/jreviews_overrides/filters/filter_functions.php

WordPress

/jreviews_overrides/filters/filter_functions.php

Available Filters

Notifications

Listing Inquiry Email Payload

Description

The "modify_inquiry_sender_info" filter is used to filter the inquiry email payload before the email is sent.

Usage

When the "modify_inquiry_sender_info" filter is called, it is passed two arguments. The first argument is an associative array with the email payload ($to, $bcc, $fromEmail, $fromName, $subject, $body). The second argument is an associative array with context data for the $listing and $event that triggered the email. $event is an object that allows retrieving sender user ID and IP address information.

Examples

Modify sender name and email

By default when an inquiry email is sent, the sender name and e-mail address are populated with the information entered in the inquiry form. This allows the recipient of the inquiry to reply directly to the sender. However, in some cases, you may not want the recipient to reply directly to the sender and you can use this filter to modify the email values before it is sent.

function modify_inquiry_sender_info($payload)
{
   $payload['fromEmail'] = '[email protected]';
 
   $payload['fromName'] = 'John Smith';
 
   return $payload;
}
 
Clickfwd\Hook\Filter::add('listing_inquiry_email_payload', 'modify_inquiry_sender_info', 10);

Asset Manager

Asset Manager Stylesheets

Description

Usage

 266:    self::$css = Hook::filter('asset_manager_stylesheets', self::$css);

Asset Manager Scripts

Description

Usage

 312:    self::$js = Hook::filter('asset_manager_scripts', self::$js);

Metatags

Page Title

Description

Usage

 182:    $title = Hook::filter('page_title_metatag', $title, $params);

Page Robots Metatag

Description

Usage

 160:    $robots = Hook::filter('page_robots_metatag', $robots, $params);

Page Keywords Metatag

Description

Usage

 202:    $keywords = Hook::filter('page_keywords_metatag', $keywords, $params);

Page Description Metatag

Description

Usage

 214:    $description = Hook::filter('page_description_metatag', $description, $params);

Page Canonical Metatag

Description

Usage

 226:    $canonical = Hook::filter('page_canonical_metatag', $canonical, $params);

Page Prev Metatag

Description

Usage

 238:    $prev = Hook::filter('page_prev_metatag', $prev, $params);

Page Next Metatag

Description

Usage

 248:    $next = Hook::filter('page_next_metatag', $next, $params);

Listing Detail

Listing Detail Action Buttons

Description

Usage

 541:    $menuExtras = Clickfwd\Hook\Filter::filter('listing_detail_action_buttons', $menuExtras, [['listing'=>$listing]]);

Listing Permissions

Trusted On Listing Create

Description

Usage

  57:    return $this->filteredResponse($trust,'trusted_on_listing_create');

Listing Allows Claims

Description

Usage

  85:    return $this->filteredResponse($permission,'listing_allows_claims',$listing);

Listing Allows Inquiries

Description

Usage

 132:    return $this->filteredResponse($permission,'listing_allows_inquiries',$listing);


Listing Allows Favorites

Description

Usage

 150:    return $this->filteredResponse($permission,'listing_allows_favorites',$listing);

Listing Allows User Reviews

Description

Usage

 173:    return $this->filteredResponse($permission,'listing_allows_user_reviews',$listing);

Listing Allows Editor Reviews

Description

Usage

 191:    return $this->filteredResponse($permission,'listing_allows_editor_reviews',$listing);

Listing User Reviews Open

Description

Usage

 207:    return $this->filteredResponse($permission,'listing_user_reviews_opened',$listing);

Listing Editor Reviews Open

Description

Usage

 223:    return $this->filteredResponse($permission,'listing_editor_reviews_opened',$listing);

Can Create Listing

Description

Usage

 251:    $permission = $this->filteredResponse($permission,'can_create_listing',[$listingTypeId]);

Can Update Listing

Description

Usage

 278:    return $this->filteredResponse($permission,'can_update_listing',$listing);

Can Add Listing Metadata

Description

Usage

 296:    return $this->filteredResponse($permission,'can_add_listing_metadata',$listingType);

Can User WYSIWYG Editor in Listing

Description

Usage

 312:    return $this->filteredResponse($permission,'can_use_editor_in_listing',[]);

Can Publish Listing

Description

Usage

 334:    return $this->filteredResponse($permission,'can_publish_listing',$listing);

Can Delete Listing

Description

Usage

 356:    return $this->filteredResponse($permission,'can_delete_listing',$listing);

Can Claim Listing

Description

Usage

 374:    return $this->filteredResponse($permission,'can_claim_listing',$listing);
 

Can Send Listing Inquiry

Description

Usage

 390:    return $this->filteredResponse($permission,'can_send_listing_inquiry',$listing);
 

Can Favorite Listing

Description

Usage

 406:    return $this->filteredResponse($permission,'can_favorite_listing',$listing);
 

Can Feature Listing

Description

Usage

 420:    return $this->filteredResponse($permission,'can_feature_listing',[]);

Can Create User Review For Listing

Description

Usage

 496:    return $this->filteredResponse($permission,'can_create_user_review_for_listing',$listing,$this->getMessage());

Can Create Editor Review For Listing

Description

Usage

 546:    return $this->filteredResponse($permission,'can_create_editor_review_for_listing',$listing,$this->getMessage());

Can Add Review on Listing Create

Description

Usage

 564:    return $this->filteredResponse($permission,'can_add_review_on_listing_create',$listingType);

Can Update Listing Media

Description

Usage

 586:    return $this->filteredResponse($permission,'can_update_listing_media',[$listing,$listingType]);

Can Upload Listing Media

Description

Usage

 624:    return $this->filteredResponse($permission,'can_upload_listing_media',[$listing,$listingType]);

Can Upload Listing Media From URL

Description

Usage

 644:    return $this->filteredResponse($permission,'can_upload_media_from_url_in_listing',$listing);

Can Upload Listing Photo

Description

Usage

 662:    return $this->filteredResponse($permission,'can_upload_listing_photo',[$listing,$listingType]);

Can Upload Listing Video

Description

Usage

 680:    return $this->filteredResponse($permission,'can_upload_listing_video');

Can Upload Listing Audio

Description

Usage

 698:    return $this->filteredResponse($permission,'can_upload_listing_audio',[$listing,$listingType]);

Can Upload Listing Attachment

Description

Usage

 716:    return $this->filteredResponse($permission,'can_upload_listing_attachment',[$listing,$listingType]);

Media Permissions

  30:    return $this->filteredResponse($trust,'trusted_on_create_photo');
  49:    return $this->filteredResponse($trust,'trusted_on_create_video');
  68:    return $this->filteredResponse($trust,'trusted_on_create_audio');
  87:    return $this->filteredResponse($trust,'trusted_on_create_attachment');
 105:    return $this->filteredResponse($permission,'media_allows_voting',$listing);
 121:    return $this->filteredResponse($permission,'media_allows_report',$listing);
 149:    return $this->filteredResponse($permission,'can_update_media_in_listing',[$listing,$media]);
 177:    return $this->filteredResponse($permission,'can_delete_media_in_listing',[$listing,$media]);
 205:    return $this->filteredResponse($permission,'can_publish_media_in_listing',[$listing,$media]);
 237:    return $this->filteredResponse($permission,'can_set_main_media',[$listing,$media]);
 259:    return $this->filteredResponse($permission,'can_update_media_details',[$listing,$media]);
 286:    return $this->filteredResponse($permission,'can_vote_on_media',[$listing,$media]);
 302:    return $this->filteredResponse($permission,'can_report_media',$listing);
 323:    return $this->filteredResponse($permission,'can_download_attachment',$media);

Review Permissions

  28:    return $this->filteredResponse($trust,'trusted_on_user_review_create');
  45:    return $this->filteredResponse($trust,'trusted_on_user_review_update');
  58:    return $this->filteredResponse($trust,'trusted_on_editor_review_create');
  71:    return $this->filteredResponse($trust,'trusted_on_editor_review_update');
  84:    return $this->filteredResponse($trust,'trusted_on_create_review_owner_reply');
 104:    return $this->filteredResponse($permission,'review_allows_report',$review);
 124:    return $this->filteredResponse($permission,'review_allows_voting',$review);
 140:    return $this->filteredResponse($permission,'review_allows_replies',$review);
 156:    return $this->filteredResponse($permission,'review_allows_discussions',$review);
 180:    return $this->filteredResponse($permission,'can_update_review',$review);
 204:    return $this->filteredResponse($permission,'can_reply_to_review',[$listing,$review]);
 220:    return $this->filteredResponse($permission,'can_delete_review_reply',$listing);
 236:    return $this->filteredResponse($permission,'can_report_review',$review);
 261:    return $this->filteredResponse($permission,'can_vote_on_review',$review);
 279:    return $this->filteredResponse($permission,'can_create_review_post',$review);
 319:    return $this->filteredResponse($permission,'can_upload_review_media',$review);
 337:    return $this->filteredResponse($permission,'can_upload_media_from_url_in_review',$review);
 353:    return $this->filteredResponse($permission,'can_upload_review_photo',$review);
 369:    return $this->filteredResponse($permission,'can_upload_review_video',$review);
 385:    return $this->filteredResponse($permission,'can_upload_review_audio',$review);
 401:    return $this->filteredResponse($permission,'can_upload_review_attachment',$review);

Review Discussion Permissions

  26:    return $this->filteredResponse($trust,'trusted_on_create_review_discussion');
  48:    return $this->filteredResponse($permission,'review_discussion_allows_report',$post);
  64:    return $this->filteredResponse($permission,'can_report_review_discussion',$post);
  86:    return $this->filteredResponse($permission,'can_update_review_discussion',[$post,$review]);
 108:    return $this->filteredResponse($permission,'can_delete_review_discussion',[$post,$review]);

Field Permissions

  59:    return $this->filteredResponse($permission,'can_view_field_in_'.$location.'_page',$field);
  87:    return $this->filteredResponse($permission,'can_read_field',[$fname]);
 115:    return $this->filteredResponse($permission,'can_write_field',[$fname]);