Skip to content

Instantly share code, notes, and snippets.

@Odyno
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Odyno/8b338c7d202125ada3dd to your computer and use it in GitHub Desktop.
Save Odyno/8b338c7d202125ada3dd to your computer and use it in GitHub Desktop.
Create a custom photos presentation from wppa+... retrive photo info
<?php
if (!class_exists("WPPAEF_Element")) :
class WPPAEF_Element {
var $id, //PhotoID
$timestamp, //Photo Time
$owner, //Owner
$owner_url, //Owner Home
$title, //Title
$description, //Descripions
$url, //Url on single photo page
$alternative_text, //Alternative text for image
$thumb_src, //src of thumb
$album, //the Album appartenence
$prefered_width,
$prefered_height;
}
endif;
function wppaef_get_last_updated_photo($max = 100, $album = null) {
global $wpdb;
global $wppa_opt;
$maxWith = $wppa_opt['wppa_topten_size'];
$elements = array();
//Create a query
$extra_where = "";
if ($album != null) {
$extra_where = " `album` in ( " . $album . " ) AND ";
}
$query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $extra_where . " `status` <> 'pending' ORDER BY `timestamp` DESC LIMIT " . $max;
//Run It
$resultSet = $wpdb->get_results($query, ARRAY_A);
//Get the information
if ($resultSet) {
foreach ($resultSet as $rawImageInfo) {
if ($rawImageInfo) {
$photo = new WPPAEF_Element();
$photo->id=$rawImageInfo['id'];
$photo->timestamp = $rawImageInfo['timestamp'];
//GET OWNER INFORMATION
$photo->owner = $rawImageInfo['owner'];
$photo->owner_url = wppaef_get_user_profile_link($rawImageInfo['owner']); //OTHER FUNCTION
$photo->title = esc_attr(stripslashes($rawImageInfo['name']));
$photo->description = stripslashes($rawImageInfo['description']);
$link = wppa_get_photo_url( $rawImageInfo['id']);
if ($link != null) {
$photo->url = $link ;
} else {
$photo->url = $photo->thumb_src; // safe link
}
$photo->alternative_text = esc_attr(wppa_qtrans($rawImageInfo['name']));
$photo->thumb_src = wppa_get_thumb_url($rawImageInfo['id']);
$photo->album = wppa_get_album_name($rawImageInfo['album']);
$imgstyle_a = wppa_get_imgstyle_a($photo->thumb_src, $maxWith, 'center', 'ttthumb');
$photo->prefered_width = $imgstyle_a['width'];
$photo->prefered_height = $imgstyle_a['height'];
array_push($elements, $photo);
}
} // foreach over $resultSet
}
return $elements;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment