XPHP

XPHP is an ever-growing library of scripting statements that you can use for powerful template control, widget behaviors, and more in LiveWhale.

In the below statements, you can use any of the XPHP variables from the XPHP Dictionary, or item-specific variables in widget results and details pages (i.e., "profiles_45" might be one of your custom profile fields).

XPHP Logic Operations

If/Then Example

The following examples demonstrate first, a simple check (is variable “X” empty?) and a more complicated one, using some of the tricks from the conditional functions below.

1
2
3
4
5
6
<xphp content="true">
<if var="X" value=""/>
<content>
<!-- do something here -->
</content>
</xphp>
1
2
3
4
5
6
<xphp content="true">
<if var="server_path" value="{group_directory}index.php"/>
<content>
<!-- show this if it's the group homepage -->
</content>
</xphp>

Whatever is in-between <content></content> will be shown if the if statement is true. It could be simple HTML, a widget, or more XPHP code.

If/Then Shorthand (1.7+)

Since LiveWhale 1.7, the above syntax can be shortened to <xphp if. For example:

1
2
3
<xphp if="X">Variable X exists.</xphp>
<xphp if="X" value="Y">Variable X has value Y.</xphp>
<xphp if="X" matches="Y">Variable X contains the text Y.</xphp>

If/Else Example

Below is an example using If/Else in xphp to display a default image in your profile details page when the person does not have a photo:

1
2
3
4
5
6
7
8
9
10
11
<xphp content="true">
<if var="profiles_image"/>
<content>
<xphp var="profiles_image"/>
</content>
<else content="true">
<content>
<img src="/path/to/default_image.png"/>
</content>
</else>
</xphp>

In this example, we see we can use <xphp var="foo"/> to display an XPHP variable directly.

AND & OR Operators

By default, XPHP if statements are treated as ANDs when two or more variables must meet the conditions set, but you can switch to an OR relationship with the addition of only one attribute on the surrounding <xphp> tag.

1
2
3
4
5
6
7
8
<!-- the default AND state -->
<xphp content="true">
<if var="a"/>
<if var="b"/>
<content>
<p>A and B are both non-empty.</p>
</content>
</xphp>
1
2
3
4
5
6
7
8
<!-- with the addition of the ifmode="or" attribute, the comparison becomes an OR -->
<xphp content="true" ifmode="or">
<if var="a"/>
<if var="b"/>
<content>
<p>Either A or B is non-empty.</p>
</content>
</xphp>

XPHP Conditional Functions

You can alter the <if> statements above, mixing and matching from the following library, to execute all sorts of logical tests:

Description Code
Does variable foo exist and have a non-empty value? <if var="foo"/>
Does variable foo not exist or have an empty value? <if var="foo value=""/>
Does variable foo equal “bar”? <if var="foo" value="bar"/>
Does variable foo not equal “bar”? <if var="foo" not_equals="bar"/>
Does variable foo equal variable bar? <if var="foo" value="{bar}"/>
Does variable foo (a comma-separated list) contain value “bar”? <if var="foo" contains="bar"/>
Does variable foo contain the text “bar” anywhere in it? <if var="foo" matches="bar"/>
Does variable foo not contain the text “bar” anywhere in it? <if var="foo" not_matches="bar"/>
Does the tag foo exist on this page/item? <if var="has_tag_foo"/>
Is variable foo (a number) less than 100?
For dates, can use “today”, “yesterday”, etc as values.
<if var="foo" less_than="100"/>
Or: <if var="foo" before="yesterday"/>
Is variable foo (a number) greater than 100?
For dates, can use “today”, “yesterday”, etc as values.
<if var="foo" greater_than="100"/>
Or: <if var="foo" after="today"/>
Is variable foo (a number) in between 5 and 7 (inclusive)? <if var="foo" range="5 to 7"/>
Does variable foo match the regular expression "~^This.+?test"?~"? <if var="foo" regexp="^This.+?test"/>
Does variable foo not match the regular expression "~^This.+?test"?~"? <if var="foo" not_regexp="^This.+?test"/>

Using other variables (POST, GET) in your if statements

By default, the above tests will check for your variables in the XPHP Dictionary (also known as $_GLOBALS in PHP). You can use the type attribute to check variables from server, get, or post.

Variable Code
From URL string: ?foo=bar <if var="foo" type="get" ...
From form (POST) to page <input name="foo"> <if var="foo" type="post" ...
From the PHP server variables <if var="foo" type="server" ...

Checking for elements on the page

You can also use XPHP to check for certain elements in the source code of the current page, using the has_element function. Your check can match any valid single CSS selector in the following forms:

1
2
3
4
5
6
7
8
<if has_element="span"/>
<if has_element="#aaa"/>
<if has_element=".bbb"/>
<if has_element="span#aaa"/>
<if has_element="span.bbb"/>
<if has_element="span#aaa.bbb"/>
<if has_element="#aaa.bbb"/>
<if has_element="#aaa.bbb.ccc"/>

This is especially useful if, for example, you want a section of your page to display only if <div id="sidebar"> exists (<if has_element="div#sidebar"/>).

Note: The element must exist in the page before the <if> statement in question is reached. This may mean, if you have other page changes being output from another XPHP statement, it could not be caught by this logical test.

XPHP Tools

In addition to the above conditional statements and logical tests, XPHP has several tools that you can use to make your website more responsive, intelligent, or fun.

Function Code
Display a random integer from 5 to 10. <xphp random="5,10"/>
Limit the output of variable foo to 10 words. <xphp var="foo" words="10"/>
Limit the output of variable foo to 10 characters. <xphp var="foo" length="10"/>
Display variable foo encoded for use in a URL (i.e., variable casting)
Allowed variable casts are: dashed, encoded, decoded, text, urlencoded, obfuscated, int, bool, float, or string
<xphp var="foo" cast="urlencoded"/>

Timely Content

You can use XPHP to show content before/after a certain date, or daily before/after a certain time.

1
2
3
4
5
6
7
8
9
<xphp content="true" before_date="12pm">
<content>Good morning!</content>
</xphp>
<xphp content="true" after_date="12pm" before_date="5pm">
<content>Good afternoon!</content>
</xphp>
<xphp content="true" after_date="5pm">
<content>Good night!</content>
</xphp>
1
2
3
4
5
6
<xphp content="true" before_date="11/28/2017">
<content>Countdown to our Day of Giving...</content>
</xphp>
<xphp content="true" after_date="11/28/2017">
<content>Today is Day of Giving!</content>
</xphp>

Using XPHP Variables Inside Quotes

In LiveWhale 1.6.2+, you can use the following XHTML-friendly syntax to place XPHP variables inside other XPHP or HTML tags and attributes. You do so by replacing <xphp var="my_variable" /> with %%xphp_my_variable%%. For example, if you have <xphp var="start_date" /> set, you can use:

1
2
3
<xphp content="true" after_date="%%xphp_start_date%%">
<content>Today is Day of Giving!</content>
</xphp>

Or even in simpler cases, you can use the %% format where you want to nest XPHP code inside other tags:

1
2
This is the URL: <xphp var="href" />
<a href="%%xphp_href%%">Read more</a>

Note, this syntax only works for individual XPHP variables and not for larger chunks of XPHP logic.

Specifying Type and Cast

In LiveWhale 1.7+, you can also use the %%xphp_ format for variables of alternate types (GET, POST, COOKIE, SERVER) and casts (encoded, decoded, text, urlencoded, obfuscated, uppercase, lowercase, uppercase-first, uppercase-words, int, bool, float, string).

The format is %%xphp_variable|TYPE|CAST:value%% with |TYPE and |CAST:value both being optional. You can also use multiple casts by separating them with spaces. A few examples are below:

<xphp> syntax %%xphp%% syntax
<xphp var="foo" /> %%xphp_foo%%
<xphp var="foo" type="GET" /> %%xphp_foo|GET%%
<xphp var="foo" cast="urlencoded" /> %%xphp_foo|CAST:urlencoded%%
<xphp var="foo" cast="urlencoded lowercase" /> %%xphp_foo|CAST:urlencoded lowercase%%
<xphp var="foo" type="POST" cast="lowercase" /> %%xphp_foo|POST|CAST:lowercase%%

XPHP Variables Dictionary

Server Variables

Variable Code
server_host <xphp var="server_host" />
server_path <xphp var="server_path" />
server_file <xphp var="server_file" />
server_filename <xphp var="server_filename" />
server_basename <xphp var="server_basename" />
server_extension <xphp var="server_extension" />
server_dirname <xphp var="server_dirname" />
server_request_uri <xphp var="server_request_uri" />
server_query_string <xphp var="server_query_string" />

Page Variables

Variable Description Code
page_title Page title of current page <xphp var="page_title" />
page_last_modified Timestamp of last edit (ex., “Nov. 7th at 2:22pm”) <xphp var="page_last_modified" />
page_last_editor Name of user who last edited <xphp var="page_last_editor" />
page_description Description <xphp var="page_description" />
page_keywords List of keywords <xphp var="page_keywords" />
page_tags List of tags selected <xphp var="page_tags" />

Group Variables

Variable Description Code
group_title Group title <xphp var="group_title" />
group_directory Name of group directory <xphp var="group_directory" />
group_fullname Full name of group <xphp var="group_fullname" />
group_link Path to group <xphp var="group_link" />
group_gid Numeric value of the Group ID <xphp var="group_gid" />
group_navigation <xphp var="group_navigation" />
group_breadcrumb <xphp var="group_breadcrumb" />
group_twitter_name <xphp var="group_twitter_name" />
group_twitter_link <xphp var="group_twitter_link" />
group_twitter_feed <xphp var="group_twitter_feed" />
group_facebook_name <xphp var="group_facebook_name" />
group_facebook_link <xphp var="group_facebook_link" />
group_facebook_feed <xphp var="group_facebook_feed" />
group_instagram_name <xphp var="group_instagram_name" />
group_instagram_link <xphp var="group_instagram_link" />
group_instagram_feed <xphp var="group_instagram_feed" />

Note: Groups that use the main navigation of another group also inherit all group_* variables from that group.

Events

Variable Description Code
events_id Events ID (ex., 4) <xphp var="events_id" />
events_parent <xphp var="events_parent" />
events_gid Group ID <xphp var="event_gid" />
events_title Title of event <xphp var="events_title" />
events_status Hidden or Live Status is returned <xphp var="events_status" />
events_is_canceled Returns true or false is event is cancelled <xphp var="events_is_canceled" />
events_summary Summary <xphp var="events_summary" />
events_description Description <xphp var="events_desciption" />
events_views Number of views <xphp var="events_views" />
events_date_dt 2014-11-22 14:00:00 <xphp var="events_date_dt" />
events_date2_dt 2014-11-22 17:00:00 <xphp var="events_date2_dt" />
events_timezone Timezone <xphp var="events_timezone" />
events_is_all_day Returns true/false if event is all day <xphp var="events_is_all_day" />
events_repeats Returns true/false if a repeating event <xphp var="events_repeats" />
events_repeats_from Starting date (2014-11-22 14:00:00) <xphp var="events_repeats_from" />
events_repeats_until Ending date (2014-11-29 14:00:00) <xphp var="events_repeats_until" />
events_repeats_occurrences <xphp var="events_repeats_occurrences" />
events_has_registration Returns true or false if there is registration <xphp var="events_has_registration" />
events_registration_owner_email Email of registration owner <xphp var="events_registration_owner_email" />
events_has_wait_list Returns true/false if event has a waiting list <xphp var="events_has_wait_list" />
events_last_modified Timestamp of last edit (ex., “Nov. 7th at 2:22pm”) <xphp var="events_last_modifed" />
events_url URL to event <xphp var="events_url" />
events_source <xphp var="events_source" />
events_cost Cost of event <xphp var="events_cost" />
events_contact_info Contact Information <xphp var="events_contact_info" />
events_is_starred Returns true/false if event is starred <xphp var="events_is_starred" />
events_subscription_id Subscription ID <xphp var="events_subscription_id" />
events_subscription_status <xphp var="events_subscription_status" />
events_location Location title and address <xphp var="events_location" />
events_location_latitude Latitude coordinate of locations (ex., 41.40338) <xphp var="events_location_latitude" />
events_location_longitude Longitude coordinate of locations (ex., 2.17403) <xphp var="events_location_longitude" />
events_tags List of tags selected <xphp var="events_tags" />
events_image <xphp var="events_image" />
events_group_title <xphp var="events_group_title" />
events_has_comments <xphp var="events_has_comments" />
events_registration_instructions <xphp var="events_registration_instructions" />
events_registration Displays registration instructions, registration form, and any additional RSVP forms that are attached (1.6+) <xphp var="events_registration"/>
events_is_paid True/false if this is a paid event <xphp var="events_is_paid" />
events_payment_price Cost of event <xphp var="events_payment_price" />
events_payment_method Method of payment <xphp var="events_payment_method" />
events_style <xphp var="events_style" />
events_group_fullname Fullname of group event is stored <xphp var="events_group_fullname" />
events_group_directory Directory path of event’s group <xphp var="events_group_directory" />
events_tags_calendar List of tags selected <xphp var="events_tags_calendar" />
events_gateway <xphp var="events_gateway" />
events_registration_open <xphp var="events_registration_open" />
events_last_editor Name of user who last edited <xphp var="events_last_editor" />
events_rsvp_form Displays RSVP form <xphp var="events_rsvp_form" />
events_images <xphp var="events_images" />
events_related_content Related Content (galleries, web links, etc..) <xphp var="events_related_content" />
events_date_ts Returns in the following format: 1416664800 <xphp var="events_date_ts" />
events_date_utc Starting date/time (2014-11-22 14:00:00) <xphp var="events_date_utc" />
events_date_time Time (12:00pm - 12:45pm) <xphp var="events_date_time" />
events_start_time Start time (12:00pm) <xphp var="events_start_time" />
events_date Date and Time (12:00pm - 12:45pm CST December 3) <xphp var="events_date" />
events_date2_time End Time (12:45pm) <xphp var="events_date2_time" />
events_image_src URL of uploaded image <xphp var="events_image_src" />
events_hero_image Displays large version of upload image <xphp var="events_hero_image" />
events_thumbnail_href URL of thumbnail <xphp var="events_thumbnail_href" />
events_thumbnail Displays thumbnail <xphp var="events_thumbnail" />
events_ical Displays “Download ical event” link <xphp var="events_ical" />
events_ical_link URL to ical feed <xphp var="events_ical_link" />
events_timestamp Start date in following format: 1416664800 <xphp var="events_timestamp" />
events_timestamp_end End date in following format: 1416675600 <xphp var="events_timestamp_end" />
events_share Returns true/false if shared to other groups <xphp var="events_share" />
events_cal_date Displays in stack format:
Nov
22
<xphp var="events_cal_date" />
events_save_to_calendar Displays “Add to Calendar” button <xphp var="events_save_to_calendar" />

Forms

Variable Description Code
forms_title Form Title <xphp var="forms_title" />
forms_last_modified Timestamp of last edit (ex., “Nov. 7th at 2:22pm”) <xphp var="forms_last_modified" />
forms_last_editor Name of user who last edited <xphp var="forms_last_editor" />
forms_tags List of tags selected <xphp var="forms_tags" />
forms_group_title Title of group forms is stored in <xphp var="forms_group_title" />

Galleries

Variable Description Code
galleries_id Gallery ID <xphp var="galleries_id" />
galleries_title Gallery Title <xphp var="galleries_title" />
galleries_date Gallery Date entered in field (11/06/2014) <xphp var="galleries_date" />
galleries_description Description <xphp var="galleries_description" />
galleries_image Displays image <xphp var="galleries_image" />
galleries_thumbnails Displays all thumbnail images <xphp var="galleries_thumbnails" />
galleries_thumbnail Displays thumbnail <xphp var="galleries_thumbnail" />
galleries_thumbnail_href URL to thumbnail <xphp var="galleries_thumbnail_href" />
galleries_location Returns Title and address of location <xphp var="galleries_location" />
galleries_location_title Location title <xphp var="galleries_location_title" />
galleries_location_latitude Latitude coordinate of locations (ex., 41.40338) <xphp var="galleries_location_latitude" />
galleries_location_longitude Longitude coordinate of locations (ex., 2.17403) <xphp var="galleries_location_longitude" />
galleries_galleryphotos <xphp var="galleries_galleryphotos" />
galleries_related_content Related Content (galleries, web links, etc..) <xphp var="galleries_related_content" />
galleries_share Returns true/false if shared to other groups <xphp var="galleries_share" />
galleries_gid Numerical value of Group ID (ex., 4) <xphp var="galleries_gid" />
galleries_group_title Name of group gallery is stored in <xphp var="galleries_group_title" />
galleries_group_directory Directory path to group <xphp var="galleries_group_directory" />
galleries_status Returns Hidden or Live status <xphp var="galleries_status" />
galleries_views Number of views of gallery <xphp var="galleries_views" />
galleries_url URL to gallery <xphp var="galleries_url" />
galleries_last_modified Timestamp of last edit (ex., “Nov. 7th at 2:22pm”) <xphp var="galleries_last_modified" />
galleries_has_comments Returns true/false if comments exist <xphp var="galleries_has_comments" />
galleries_last_editor Name of user who last edited <xphp var="galleries_last_editor" />
galleries_galleries_url <xphp var="galleries_galleries_url" />
galleries_tags List of tags selected <xphp var="galleries_tags" /> ​ ​

News

Variable Description Code
news_id News ID <xphp var="news_id" />
news_gid Group ID <xphp var="news_gid" />
news_group_title Group name <xphp var="news_group_title" />
news_group_directory Directory path to group <xphp var="news_group_directory" />
news_headline Headine <xphp var="news_headline" />
news_summary Summary of the news story <xphp var="news_summary" />
news_date News date (ex., May 17, 2017) <xphp var="news_date" />
news_date_dt News datetime (ex., 2017-11-07 06:00:00) <xphp var="news_date_dt" />
news_body News story body <xphp var="news_body" />
news_url URL to the news story <xphp var="news_url" />
news_status Hidden or Live news story <xphp var="news_status" />
news_views Number of views of story received <xphp var="news_views" />
news_last_modified Timestamp of last edit (ex., “Nov. 7th at 2:22pm”) <xphp var="news_last_modified" />
news_has_comments Returns true or false if comments exist <xphp var="news_has_comments" />
news_last_editor Name of user who last edited the story <xphp var="news_last_editor" />
news_news_url <xphp var="news_news_url" />
news_tags List of starred tags selected <xphp var="news_tags" />
news_location Name and address of location <xphp var="news_location" />
news_location_title Name of location <xphp var="news_location_title" />
news_location_longitude Longitude coordinate of locations (ex., 2.17403) <xphp var="news_location_longitude" />
news_related_content Related Content (galleries, web links, etc..) <xphp var="news_related_content" />
news_date Story date entered in date field <xphp var="news_date" />
news_thumbnail Displays thumbnail image <xphp var="news_thumbnail" />
news_thumbnail_href URL to thumbnail image (available in 1.6) <xphp var="news_thumbnail_href" />
news_image Displays the uploaded image <xphp var="news_image" />
news_contactinfo Information entered in Contact Information field <xphp var="news_contactinfo" />
news_share Returns true/false if shared to other groups <xphp var="news_share" />
news_views Returns the number of views from Google Analytics (LW 1.5.1+) <xphp var="news_views" /> ​

Profiles

Variable Description Code
profiles_id Numerical profile id (ex., 7) <xphp var="profiles_id" />
profiles_gid Numerical group id the profile is stored <xphp var="profiles_gid" />
profiles_tid Numerical profile type id <xphp var="profiles_tid" />
profiles_group_title Name of the group the profile is stored. (ex., Admissions) <xphp var="profiles_group_title" />
profiles_group_directory URL path to the group (ex., http://localhost.edu/admissions) <xphp var="profiles_group_directory" />
profiles_parent <xphp var="profiles_parent" />
profiles_url URL path to profile <xphp var="profiles_url" />
profiles_status Hidden or Live <xphp var="profiles_status" />
profiles_firstname First name (ex., “Jane”) <xphp var="profiles_firstname" />
profiles_middlename Middle name (ex., “Ann”) <xphp var="profiles_middlename" />
profiles_lastname last name (ex., “Smith”) <xphp var="profiles_firstname" />
profiles_title Returns data entered in title field (ex., “Director of Marketing”) <xphp var="profiles_title" />
profiles_name Full name is returned (“Jane Ann Smith”) <xphp var="profiles_name" />
profiles_style Returns the profile style (ex., person) <xphp var="profiles_style" />
profiles_description Returns data entered in Description field <xphp var="profiles_description" />
profiles_description_location <xphp var="profiles_description_location" />
profiles_last_modifed Timestamp of last edit (ex., “Nov. 7th at 2:22pm”) <xphp var="profiles_last_modified" />
profiles_contact_info Returns data entered into the Contact Information field <xphp var="profiles_contact_info" />
profiles_contact_info_location <xphp var="profiles_contact_info_location" />
profiles_views Number of profile views <xphp var="profiles_views" />
profiles_last_editor Returns name of the person who last edited the profile. <xphp var="profiles_last_editor" />
profiles_profiles_url <xphp var="profiles_profiles_url" />
profiles_tags List of tags are displayed <xphp var="profiles_tags" />
profiles_location_title Location Title <xphp var="profiles_location_title" />
profiles_location_latitude Latitude coordinate of locations (ex., 41.40338) <xphp var="profiles_location_latitiude" />
profiles_location_longitude Longitude coordinate of locations (ex., 2.17403) <xphp var="profiles_location_longitude" />
profiles_type Returns the profile type name (ex., Faculty) <xphp var="profiles_type" />
profiles_images Returns a collection of profile’s images upload <xphp var="profiles_images" />
profiles_related_content Related Content (galleries, web links, etc..) <xphp var="profiles_related_content" />
profiles_thumbnail_href URL to the image thumbnail <xphp var="profiles_thumbnail_href" />
profiles_thumbnail Displays the thumbnail image <xphp var="profiles_thumbnail" />
profiles_image Displays the uploaded image <xphp var="profiles_image" />
profiles_body Returns all data entered and set as “body” in profile type <xphp var="profiles_body" />
profiles_sidebar Returns all data entered and set as “sidebar” in profile type <xphp var="profiles_sidebar" />
profiles_share Returns true/false if shared to other groups <xphp var="profiles_share" />

Time

Variable Code
server_date_month <xphp var="server_date_month" />
server_date_day <xphp var="server_date_day" />
server_date_date <xphp var="server_date_date" />
server_date_year <xphp var="server_date_year" />
server_date_full <xphp var="server_date_full" />
server_time_full_12 <xphp var="server_time_full_12" />
server_time_full_24 <xphp var="server_time_full_24" />
server_time_hour_12 <xphp var="server_time_hour_12" />
server_time_hour_24 <xphp var="server_time_hour_24" />
server_time_minute <xphp var="server_time_minute" />
server_time_ampm <xphp var="server_time_ampm" />
server_time_timezone <xphp var="server_time_timezone" />

​Tags

Variable Description Code
tag_title Returns only the title of tag <xphp var="tag_title" />
tag_links Returns the tag link <xphp var="tag_links" />