provider = 'zenfolio';
$this->user_agent = "Photonic for " . get_home_url();
$this->link_lightbox_title = empty($photonic_zenfolio_disable_title_link);
$this->service_url = 'https://api.zenfolio.com/api/1.8/zfapi.asmx';
$this->secure_url = 'https://api.zenfolio.com/api/1.8/zfapi.asmx';
$this->unlocked_realms = [];
$this->temp_keyring = '';
$this->doc_links = [
'general' => 'https://aquoid.com/plugins/photonic/zenfolio/',
'photos' => 'https://aquoid.com/plugins/photonic/zenfolio/photos/',
'photosets' => 'https://aquoid.com/plugins/photonic/zenfolio/photosets/',
'groups' => 'https://aquoid.com/plugins/photonic/zenfolio/group/',
'hierarchies' => 'https://aquoid.com/plugins/photonic/zenfolio/group-hierarchy/',
];
$this->perform_back_end_authentication();
$this->standard_sizes = [
0 => ['w' => 80, 'h' => 80, 'c' => 0],
1 => ['w' => 60, 'h' => 60, 'c' => 1],
2 => ['w' => 400, 'h' => 400, 'c' => 0],
3 => ['w' => 580, 'h' => 450, 'c' => 0],
4 => ['w' => 800, 'h' => 630, 'c' => 0],
5 => ['w' => 1100, 'h' => 850, 'c' => 0],
6 => ['w' => 1550, 'h' => 960, 'c' => 0],
10 => ['w' => 120, 'h' => 120, 'c' => 0],
11 => ['w' => 120, 'h' => 120, 'c' => 0],
];
}
/**
* Main function that fetches the images associated with the shortcode.
*
* @param array $attr
* @return array
*/
public function get_gallery_images($attr = []): array {
global $photonic_zenfolio_thumb_size, $photonic_zenfolio_main_size, $photonic_zenfolio_tile_size, $photonic_zenfolio_title_caption, $photonic_zenfolio_video_size, $photonic_zenfolio_media, $photonic_zenfolio_default_user;
$this->push_to_stack('Get Gallery Images');
$attr = array_merge(
$this->common_parameters,
[
'caption' => $photonic_zenfolio_title_caption,
'thumb_size' => $photonic_zenfolio_thumb_size,
'main_size' => $photonic_zenfolio_main_size,
'video_size' => $photonic_zenfolio_video_size,
'tile_size' => $photonic_zenfolio_tile_size,
'count' => 500,
'offset' => 0,
'media' => $photonic_zenfolio_media,
'structure' => 'nested',
'login_name' => $photonic_zenfolio_default_user,
],
$attr
);
$attr = array_map('trim', $attr);
$attr['limit'] = empty($attr['limit']) ? $attr['count'] : $attr['limit'];
$attr['photo_count'] = empty($attr['photo_count']) ? $attr['limit'] : $attr['photo_count'];
$attr['overlay_size'] = empty($attr['overlay_size']) ? $attr['thumb_size'] : $attr['overlay_size'];
$attr['overlay_video_size'] = empty($attr['overlay_video_size']) ? $attr['video_size'] : $attr['overlay_video_size'];
if (isset($_COOKIE['photonic-zf-keyring'])) {
$realms = $this->make_wp_call('KeyringGetUnlockedRealms', ['keyring' => sanitize_text_field(wp_unslash($_COOKIE['photonic-zf-keyring']))]);
if (!empty($realms) && !empty($realms->result)) {
$this->unlocked_realms = $realms->result;
}
}
$chained_methods = [];
$zenfolio_params = [];
$attr['headers_already_called'] = true;
if (!empty($attr['view'])) {
switch ($attr['view']) {
case 'photos':
if (!empty($attr['object_id'])) {
$object_id = $attr['object_id'];
$chained_methods[] = 'LoadPhoto';
$h = stripos($object_id, 'h');
$p = stripos($object_id, 'p');
if (false !== $h) {
$object_id = substr($object_id, $h + 1);
$object_id = hexdec($object_id);
}
elseif (false !== $p) {
$object_id = substr($object_id, $p + 1);
}
elseif (strlen($object_id) === 7) {
$object_id = hexdec($object_id);
}
$zenfolio_params['photoId'] = $object_id;
$zenfolio_params['level'] = 'Full';
}
elseif (!empty($attr['text']) || !empty($attr['category_code'])) {
$zenfolio_params['searchId'] = '';
$zenfolio_params['sortOrder'] = $attr['sort_order'] ?? 'Date'; // Popularity | Date | Rank
if (!empty($attr['text'])) {
$zenfolio_params['query'] = $attr['text'];
$chained_methods[] = 'SearchPhotoByText';
}
elseif (!empty($attr['category_code'])) {
$zenfolio_params['categoryCode'] = $attr['category_code'];
$chained_methods[] = 'SearchPhotoByCategory';
}
$zenfolio_params['offset'] = $attr['offset'];
$zenfolio_params['limit'] = $attr['limit'];
}
elseif (!empty($attr['kind'])) {
$zenfolio_params['offset'] = $attr['offset'];
$zenfolio_params['limit'] = $attr['limit'];
switch ($attr['kind']) {
case 'popular':
$chained_methods[] = 'GetPopularPhotos';
break;
case 'recent':
$chained_methods[] = 'GetRecentPhotos';
break;
default:
$this->pop_from_stack();
return [
new Error(sprintf(esc_html__('Invalid %s parameter.', 'photonic'), 'kind') . Photonic::doc_link($this->doc_links['photos']))
];
}
}
else {
$this->pop_from_stack();
return [
new Error(sprintf(esc_html__('The %1$s parameter is required if %2$s is not specified.', 'photonic'), 'kind', 'object_id') . Photonic::doc_link($this->doc_links['photos']))
];
}
break;
case 'photosets':
if (!empty($attr['object_id'])) {
$object_id = $attr['object_id'];
$p = stripos($object_id, 'p');
if (false !== $p) {
$object_id = substr($object_id, $p + 1);
}
$zenfolio_params['photosetId'] = $object_id;
$zenfolio_params['level'] = 'Level2';
$zenfolio_params['includePhotos'] = false;
if (!empty($attr['password']) && empty($realm_id)) {
$first_call = $this->make_wp_call('LoadPhotoSet', $zenfolio_params);
if (isset($first_call->result) && !empty($first_call->result)) {
$photoset = $first_call->result;
if (isset($photoset->AccessDescriptor)) {
$realm_id = $photoset->AccessDescriptor->Id;
}
}
}
if (!empty($attr['password']) && !empty($realm_id)) {
if (!in_array($realm_id, $this->unlocked_realms, true)) {
$attr['headers_already_called'] = empty($attr['panel']); // false;
$chained_methods[] = 'KeyringAddKeyPlain';
$zenfolio_params['keyring'] = empty($_COOKIE['photonic-zf-keyring']) ? '' : sanitize_text_field(wp_unslash($_COOKIE['photonic-zf-keyring']));
$zenfolio_params['realmId'] = $realm_id;
$zenfolio_params['password'] = $attr['password'];
}
}
$chained_methods[] = 'LoadPhotoSet';
$zenfolio_params['startingIndex'] = $attr['offset'];
$zenfolio_params['numberOfPhotos'] = $attr['limit'];
$chained_methods[] = 'LoadPhotoSetPhotos';
}
elseif (!empty($attr['login_name'])) {
$chained_methods[] = 'LoadGroupHierarchy';
$attr['structure'] = 'flat';
$zenfolio_params['loginName'] = $attr['login_name'];
}
elseif (!empty($attr['photoset_type'])) {
$photoset_type = $attr['photoset_type'];
if (!empty($attr['text']) || !empty($attr['category_code'])) {
$zenfolio_params['searchId'] = '';
$chained_methods[] = !empty($attr['text']) ? 'SearchSetByText' : 'SearchSetByCategory';
}
elseif (!empty($attr['kind'])) {
switch ($attr['kind']) {
case 'popular':
$chained_methods[] = 'GetPopularSets';
break;
case 'recent':
$chained_methods[] = 'GetRecentSets';
break;
default:
$this->pop_from_stack();
return [
new Error(
sprintf(esc_html__('Invalid %s parameter.', 'photonic'), 'kind') .
Photonic::doc_link($this->doc_links['photosets'])
)
];
}
}
if ('gallery' === strtolower($photoset_type) || 'galleries' === strtolower($photoset_type)) {
$zenfolio_params['type'] = 'Gallery';
}
elseif ('collection' === strtolower($photoset_type) || 'collections' === strtolower($photoset_type)) {
$zenfolio_params['type'] = 'Collection';
}
else {
$this->pop_from_stack();
return [
new Error(
sprintf(esc_html__('Invalid %1$s parameter. Permissible values are %2$s or %3$s.', 'photonic'), 'photoset_type', 'Gallery', 'Collection') .
Photonic::doc_link($this->doc_links['photosets'])
)
];
}
if (!empty($attr['text']) || !empty($attr['category_code'])) {
$zenfolio_params['sortOrder'] = !empty($attr['sort_order']) ? $attr['sort_order'] : (!empty($attr['text']) ? 'Rank' : 'Date');
if (!empty($attr['text'])) {
$zenfolio_params['query'] = $attr['text'];
}
elseif (!empty($attr['category_code'])) {
$zenfolio_params['categoryCode'] = $attr['category_code'];
}
}
$zenfolio_params['offset'] = $attr['offset'];
$zenfolio_params['limit'] = $attr['limit'];
}
elseif (!empty($attr['filter']) && empty($attr['login_name'])) {
$this->pop_from_stack();
return [
new Error(
sprintf(esc_html__('The %1$s parameter is required if %2$s is specified.', 'photonic'), 'login_name', 'filter') .
Photonic::doc_link($this->doc_links['photosets'])
)
];
}
elseif (empty($attr['kind'])) {
$this->pop_from_stack();
return [
new Error(
sprintf(esc_html__('The %1$s parameter is required if %2$s or %3$s is not specified.', 'photonic'), 'kind', 'object_id', 'login_name') .
Photonic::doc_link($this->doc_links['photosets'])
)
];
}
elseif (empty($attr['photoset_type'])) {
$this->pop_from_stack();
return [
new Error(
sprintf(esc_html__('The %1$s parameter is required if %2$s or %3$s is not specified.', 'photonic'), 'photoset_type', 'object_id', 'login_name') .
Photonic::doc_link($this->doc_links['photosets'])
)
];
}
if (!empty($attr['login_name']) && !empty($attr['category_code'])) {
$attr['user_specific_category'] = true;
}
if (!empty($attr['login_name']) && !empty($attr['text'])) {
$attr['user_specific_text'] = true;
}
break;
case 'hierarchy':
if (empty($attr['login_name'])) {
$this->pop_from_stack();
return [
new Error(
sprintf(esc_html__('The %s parameter is required.', 'photonic'), 'login_name') .
Photonic::doc_link($this->doc_links['hierarchies'])
)
];
}
$chained_methods[] = 'LoadGroupHierarchy';
$zenfolio_params['loginName'] = $attr['login_name'];
break;
case 'group':
if (empty($attr['object_id'])) {
$this->pop_from_stack();
return [
new Error(
sprintf(esc_html__('The %s parameter is required.', 'photonic'), 'object_id') .
Photonic::doc_link($this->doc_links['groups'])
)
];
}
else {
$object_id = $attr['object_id'];
}
$chained_methods[] = 'LoadGroup';
$f = stripos($object_id, 'f');
if (false !== $f) {
$object_id = substr($object_id, $f + 1);
}
$zenfolio_params['groupId'] = $object_id;
$zenfolio_params['level'] = 'Full';
$zenfolio_params['includeChildren'] = true;
break;
}
}
if (!empty($attr['panel'])) {
$attr['display'] = 'modal';
}
else {
$attr['display'] = 'local';
}
$header_display = $this->get_header_display($attr);
$attr['header_display'] = $header_display;
$call_return = $this->make_chained_calls($chained_methods, $zenfolio_params, $attr);
$this->pop_from_stack();
if (!empty($this->stack_trace[$this->gallery_index])) {
$call_return[] = $this->stack_trace[$this->gallery_index];
}
return $call_return;
}
/**
* Calls a Zenfolio method with the passed parameters.
*
* @param $method
* @param null $params
* @param null $keyring
* @return array|mixed|null|object|string|string[]|WP_Error
*/
private function make_wp_call($method, $params = null, $keyring = null) {
$request = $this->prepare_request($method, $params, $keyring);
$response = $this->make_wp_request($method, $request);
return $response;
}
/**
* Makes a sequence of calls to different Zenfolio methods. This is particularly useful in case of authenticated calls, where
* first the authentication happens, then the content is displayed, all in the same call.
*
* @param array $methods
* @param array $zenfolio_args
* @param array $short_code
* @return array
*/
private function make_chained_calls($methods, $zenfolio_args, &$short_code = []) {
$this->push_to_stack('Make chained calls');
$components = [];
$keyring = null;
$original_params = [];
foreach ($zenfolio_args as $param => $value) {
$original_params[$param] = $value;
}
$pagination = new Pagination();
$pagination->start = $short_code['offset'];
$pagination->per_page = $short_code['limit'];
foreach ($methods as $method) {
$this->push_to_stack("Making call for $method");
$keyring_params = [];
if ('KeyringGetUnlockedRealms' === $method) {
$keyring_params['keyring'] = $zenfolio_args['keyring'];
$response = $this->make_wp_call($method, $keyring_params);
if (isset($response->result)) {
$this->unlocked_realms = $response->result;
}
}
elseif ('KeyringAddKeyPlain' === $method) {
if (in_array($zenfolio_args['realmId'], $this->unlocked_realms, true)) {
continue;
}
$keyring_params['keyring'] = $zenfolio_args['keyring'];
$keyring_params['realmId'] = $zenfolio_args['realmId'];
$keyring_params['password'] = $zenfolio_args['password'];
$response = $this->make_wp_call($method, $keyring_params);
if (!empty($response->result)) {
// Sometimes the cookie isn't set by the setcookie command (happens when the password is passed as a shortcode parameter
// instead of the password prompt)
$keyring = $response->result;
if (!in_array($keyring_params['realmId'], $this->unlocked_realms, true)) {
$this->unlocked_realms[] = $keyring_params['realmId'];
$this->temp_keyring = $keyring;
}
if (!$short_code['headers_already_called']) {
setcookie('photonic-zf-keyring', $keyring, time() + 60 * 60 * 24, COOKIEPATH);
}
}
else {
$components[] = $this->password_protected;
break;
}
}
else {
foreach ($original_params as $param => $value) {
$zenfolio_args[$param] = $value;
}
$keyring_fields = ['keyring', 'realmId', 'password'];
foreach ($zenfolio_args as $param => $value) {
if (in_array($param, $keyring_fields, true)) {
unset($zenfolio_args[$param]);
}
}
if ('LoadPhotoSetPhotos' === $method) {
unset($zenfolio_args['level']);
unset($zenfolio_args['includePhotos']);
}
elseif ('LoadPhotoSet' === $method) {
unset($zenfolio_args['startingIndex']);
unset($zenfolio_args['numberOfPhotos']);
}
$response = $this->make_wp_call($method, $zenfolio_args, $keyring);
$this->pop_from_stack();
$this->push_to_stack('Processing response');
$components = array_merge($components, $this->process_response($method, $response, $short_code, $pagination));
$this->pop_from_stack();
}
}
$this->pop_from_stack();
return $components;
}
/**
* Routing function that takes the response and redirects it to the appropriate processing function.
*
* @param $method
* @param $response
* @param array $short_code
* @param Pagination $pagination
* @return string|array
*/
private function process_response($method, $response, &$short_code, Pagination &$pagination) {
$header_display = $short_code['header_display'];
if (!empty($response->result)) {
$result = $response->result;
$components = [];
switch ($method) {
case 'GetPopularPhotos':
case 'GetRecentPhotos':
case 'SearchPhotoByText':
case 'SearchPhotoByCategory':
$pagination->total = $result->TotalCount;
$components[] = $this->process_photos($result, 'stream', $short_code, $pagination);
break;
case 'LoadPhoto':
$component = $this->process_photo($result, $short_code);
if (!is_null($component)) {
$components[] = $component;
}
break;
case 'GetPopularSets':
case 'GetRecentSets':
case 'SearchSetByText':
case 'SearchSetByCategory':
$components[] = $this->process_sets($result, $short_code);
break;
case 'LoadPhotoSet':
case 'LoadPhotoSetPhotos':
if (isset($result->ImageCount)) {
$pagination->total = $result->ImageCount;
}
$components = array_merge($components, $this->process_set($result, ['header_display' => $header_display], $short_code, $pagination));
break;
case 'LoadGroupHierarchy':
$component = $this->process_group_hierarchy($result, ['header_display' => $header_display], $short_code);
if (!is_null($component)) {
$components[] = $component;
}
break;
case 'LoadGroup':
$component = $this->process_group($result, ['header_display' => $header_display], $short_code, 0);
if (!is_null($component)) {
$components[] = $component;
}
break;
}
return $components;
}
elseif ($response === $this->password_protected) {
return [$response];
}
elseif (!empty($response->error)) {
if (!empty($response->error->message)) {
return [new Error(esc_html__('Zenfolio returned an error:', 'photonic') . "
\n" . $response->error->message)];
}
else {
return [new Error(esc_html__('Unknown error', 'photonic'))];
}
}
else {
return [new Error(esc_html__('Unknown error', 'photonic'))];
}
}
/**
* Takes an array of photos and displays each as a thumbnail. Each thumbnail, upon clicking launches a lightbox.
*
* @param $response
* @param string $parent
* @param array $short_code
* @param Pagination|null $pagination
* @return Photo_List|Error
*/
private function process_photos($response, string $parent, array $short_code, Pagination $pagination) {
if (!is_array($response)) {
if (empty($response->Photos) || !is_array($response->Photos)) {
return new Error(esc_html__('Response is not an array', 'photonic'));
}
$response = $response->Photos;
}
global $photonic_zenfolio_photos_per_row_constraint, $photonic_zenfolio_photo_title_display, $photonic_zenfolio_photos_constrain_by_count;
$row_constraints = ['constraint-type' => $photonic_zenfolio_photos_per_row_constraint, 'count' => $photonic_zenfolio_photos_constrain_by_count];
$photo_objects = $this->build_level_1_objects($response, $short_code);
$pagination->end = $pagination->start + count($response);
$photo_list = new Photo_List($short_code);
$photo_list->photos = $photo_objects;
$photo_list->title_position = $photonic_zenfolio_photo_title_display;
$photo_list->row_constraints = $row_constraints;
$photo_list->parent = $parent;
$photo_list->pagination = $pagination;
return $photo_list;
}
public function build_level_1_objects($response, array $short_code = [], $module_parameters = [], $options = []): array {
if (!is_array($response)) {
if (empty($response->Photos) || !is_array($response->Photos)) {
return [];
}
$response = $response->Photos;
}
$tile_size = (empty($short_code['tile_size']) || 'same' === $short_code['tile_size']) ? $short_code['main_size'] : $short_code['tile_size'];
$type = '$type';
$photo_objects = [];
$media = explode(',', $short_code['media']);
$videos_ok = in_array('videos', $media, true) || in_array('all', $media, true);
$photos_ok = in_array('photos', $media, true) || in_array('all', $media, true);
$sizes = [
'thumb_size' => intval($short_code['thumb_size']),
'tile_size' => intval($tile_size),
'main_size' => intval($short_code['main_size']),
];
foreach ($response as $photo) {
if (empty($photo->$type) || 'Photo' !== $photo->$type || ($photo->IsVideo && !$videos_ok) || (!$photo->IsVideo && !$photos_ok)) {
continue;
}
$appendage = [];
if (isset($photo->Sequence)) {
$appendage[] = 'sn=' . $photo->Sequence;
}
if (isset($photo->UrlToken)) {
$appendage[] = 'tk=' . $photo->UrlToken;
}
$photonic_photo = new Photo();
$photonic_photo->thumbnail = esc_url('https://' . $photo->UrlHost . $photo->UrlCore . '-' . $short_code['thumb_size'] . '.jpg');
$photonic_photo->main_image = esc_url('https://' . $photo->UrlHost . $photo->UrlCore . '-' . $short_code['main_size'] . '.jpg');
$photonic_photo->tile_image = esc_url('https://' . $photo->UrlHost . $photo->UrlCore . '-' . $tile_size . '.jpg');
$this->calculate_sizes($photo, $photonic_photo, $sizes);
if ($photo->IsVideo) {
$photonic_photo->video = esc_url(substr($photo->OriginalUrl, 0, strlen($photo->OriginalUrl) - 7) . $short_code['video_size'] . '.mp4');
}
$photonic_photo->download = esc_url($photonic_photo->main_image . '?' . implode('&', $appendage));
$photonic_photo->title = wp_kses_post($photo->Title ?? '');
$photonic_photo->alt_title = $photonic_photo->title;
$photonic_photo->description = wp_kses_post($photo->Caption ?? '');
$photonic_photo->main_page = esc_url($photo->PageUrl);
$photonic_photo->id = $photo->Id;
if (!empty($photo->UploadedOn) && !empty($photo->UploadedOn->Value)) {
$photonic_photo->uploaded_on = sanitize_text_field($photo->UploadedOn->Value);
}
if (!empty($photo->TakenOn) && !empty($photo->TakenOn->Value)) {
$photonic_photo->taken_on = sanitize_text_field($photo->TakenOn->Value);
}
$photo_objects[] = $photonic_photo;
}
return $photo_objects;
}
public function build_level_2_objects($objects_or_response, array $short_code, array $filter_list = [], array $options = [], ?Pagination &$pagination = null): array {
global $photonic_zenfolio_hide_password_protected_thumbnail, $photonic_gallery_template_page;
$tile_size = (empty($short_code['tile_size']) || 'same' === $short_code['tile_size']) ? $short_code['main_size'] : $short_code['tile_size'];
$sizes = [
'thumb_size' => intval($short_code['thumb_size']),
'tile_size' => intval($tile_size),
];
$filter_list = [];
if (!empty($short_code['filter'])) {
$filter_list = explode(',', $short_code['filter']);
}
$objects = [];
foreach ($objects_or_response as $photoset) {
if (empty($photoset->TitlePhoto)) {
continue;
}
if (!empty($photoset->AccessDescriptor) && !empty($photoset->AccessDescriptor->AccessType) && 'Password' === $photoset->AccessDescriptor->AccessType && !empty($photonic_zenfolio_hide_password_protected_thumbnail)) {
continue;
}
$photonic_album = new Album();
$photo = $photoset->TitlePhoto;
$photonic_album->id = $photoset->Id;
$photonic_album->thumbnail = esc_url('https://' . $photo->UrlHost . $photo->UrlCore . '-' . $short_code['thumb_size'] . '.jpg');
$photonic_album->tile_image = esc_url('https://' . $photo->UrlHost . $photo->UrlCore . '-' . $tile_size . '.jpg');
$this->calculate_sizes($photo, $photonic_album, $sizes);
$photonic_album->main_page = esc_url($photoset->PageUrl);
$photonic_album->title = wp_kses_post($photoset->Title);
$photonic_album->counter = $photoset->PhotoCount;
if (!empty($photoset->AccessDescriptor) && !empty($photoset->AccessDescriptor->AccessType) && 'Password' === $photoset->AccessDescriptor->AccessType) {
if (!in_array($photoset->AccessDescriptor->Id, $this->unlocked_realms, true)) {
$photonic_album->classes = ['photonic-zenfolio-passworded'];
$photonic_album->passworded = 1;
$photonic_album->realm_id = $photoset->AccessDescriptor->Id;
$photonic_album->data_attributes['realm'] = $photoset->AccessDescriptor->Id;
}
}
$internal_short_code = $short_code;
$internal_short_code['view'] = 'photosets';
$internal_short_code['object_id'] = $photoset->Id;
$internal_short_code['layout'] = empty($short_code['photo_layout']) ? $short_code['layout'] : $short_code['photo_layout'];
$internal_short_code['limit'] = empty($short_code['photo_count']) ? $short_code['limit'] : $short_code['photo_count'];
$internal_short_code['more'] = empty($short_code['photo_more']) ? $short_code['more'] : $short_code['photo_more'];
if ('page' === $short_code['popup'] && !empty($photonic_gallery_template_page) && is_string(get_post_status($photonic_gallery_template_page))) {
$photonic_album->gallery_url = $this->get_gallery_url(
$internal_short_code,
[
'title' => $photonic_album->title,
]
);
}
$page_url = wp_parse_url($photoset->PageUrl);
$page_url = $page_url['path'];
$page_url = explode('/', $page_url);
if (count($page_url) > 1) {
$page_url = $page_url[1];
}
if (!is_array($page_url) && (count($filter_list) === 0 || (count($filter_list) > 0 && in_array($page_url, $filter_list, true) && 'exclude' !== strtolower($short_code['filter_type'])) ||
(count($filter_list) > 0 && !in_array($page_url, $filter_list, true) && 'exclude' === strtolower($short_code['filter_type'])))) {
$objects[] = $photonic_album;
}
elseif (is_array($page_url)) { // Something went wrong. Let's be safe and add the object.
$objects[] = $photonic_album;
}
}
return $objects;
}
private function calculate_sizes($photo, &$object, $sizes) {
$width = $photo->Width;
$height = $photo->Height;
$aspect_ratio = 0;
if ($width && $height) {
$aspect_ratio = $width / $height;
}
if ($aspect_ratio > 0) {
foreach ($sizes as $size => $size_value) {
if ($width >= $this->standard_sizes[$size_value]['w'] || $height >= $this->standard_sizes[$size_value]['h']) {
$object->{$size} = [
'w' => (1 === $size_value) ? 60 : ($aspect_ratio > 1 ? $this->standard_sizes[$size_value]['w'] : ($this->standard_sizes[$size_value]['h'] * $aspect_ratio)),
'h' => (1 === $size_value) ? 60 : ($aspect_ratio < 1 ? $this->standard_sizes[$size_value]['h'] : ($this->standard_sizes[$size_value]['w'] / $aspect_ratio)),
];
}
else {
$object->{$size} = [
'w' => (1 === $size_value) ? 60 : $width,
'h' => (1 === $size_value) ? 60 : $height,
];
}
}
}
}
/**
* Prints a single photo with the title as an