Files
IPB/upload/sources/api/gallery/api_gallery.php
T
2025-12-19 00:22:37 -08:00

189 lines
4.6 KiB
PHP

<?php
/*
+--------------------------------------------------------------------------
| Invision Power Board
| =============================================
| by Matthew Mecham
| (c) 2001 - 2006 Invision Power Services, Inc.
| http://www.invisionpower.com
| =============================================
| Web: http://www.invisionboard.com
| Licence Info: http://www.invisionboard.com/?license
+---------------------------------------------------------------------------
| > $Date: 2005-10-10 14:08:54 +0100 (Mon, 10 Oct 2005) $
| > $Revision: 23 $
| > $Author: matt $
+---------------------------------------------------------------------------
|
| > API: Gallery last 5 submissions
| > Module written by Brandon Farber
| > Date started: Wednesday 7/26/2006
|
+--------------------------------------------------------------------------
*/
/**
* API: Gallery
*
* EXAMPLE USAGE
* <code>
* To follow
* </code>
*
* @package InvisionPowerBoard
* @subpackage APIs
* @author Brandon Farber
* @copyright Invision Power Services, Inc.
* @version 2.1
*/
if ( ! defined( 'IPS_API_PATH' ) )
{
/**
* Define classes path
*/
define( 'IPS_API_PATH', dirname(__FILE__) ? dirname(__FILE__) : '.' );
}
if ( ! class_exists( 'api_core' ) )
{
require_once( IPS_API_PATH.'/api_core.php' );
}
/**
* API: Gallery
*
* This class will pull the last 5 images a user has submitted to Gallery.
*
* @package InvisionPowerBoard
* @subpackage APIs
* @author Brandon Farber
* @version 2.1
* @since 2.2.0
*/
class api_gallery extends api_core
{
/**
* IPS Class Object
*
* @var object
*/
//var $ipsclass;
/*-------------------------------------------------------------------------*/
// Returns an array of gallery data
/*-------------------------------------------------------------------------*/
/**
* Returns an array of gallery data
*
* @return array Array of gallery data
*/
function return_gallery_data( $member_id = 0, $limit = 5, $do_pull = 1 )
{
if( !$member_id )
{
return array();
}
//-----------------------------------------
// Permissions?
//-----------------------------------------
if( !$this->ipsclass->vars['gallery_guest_access'] AND !$this->ipsclass->member['id'] )
{
return array();
}
//-----------------------------------------
// INIT
//-----------------------------------------
$images = array();
$member_id = intval($member_id);
$categories = $this->glib->get_allowed_cats( 0 );
$albums = $this->glib->get_allowed_albums();
if( !count($categories) AND !count($albums) )
{
return array();
}
$where = array();
$where_statement = "";
if( count($categories) )
{
$where[] = "i.category_id IN (".implode( ',', $categories ).")";
}
if( count($albums) )
{
$where[] = "i.album_id IN (".implode( ",", $albums ).")";
}
if( !count($where) )
{
return array();
}
else
{
$where_statement = implode( " OR ", $where );
}
$this->ipsclass->DB->build_query( array( 'select' => 'i.*',
'from' => array( 'gallery_images' => 'i' ),
'where' => "i.member_id={$member_id} AND ({$where_statement})",
'add_join' => array(
1 => array( 'type' => 'left',
'select' => 'a.name as album_name, a.public_album',
'from' => array( 'gallery_albums' => 'a' ),
'where' => 'a.id=i.album_id',
),
2 => array( 'type' => 'left',
'select' => 'c.name as category_name',
'from' => array( 'gallery_categories' => 'c' ),
'where' => "c.id=i.category_id",
),
3 => array( 'type' => 'left',
'select' => 'm.members_display_name as name',
'from' => array( 'members' => 'm' ),
'where' => "m.id=i.member_id",
),
4 => array( 'type' => 'left',
'select' => 'r.id as rated, r.rate as _my_rate',
'from' => array( 'gallery_ratings' => 'r' ),
'where' => "r.img_id=i.id AND r.member_id={$this->ipsclass->member['id']}",
)
),
'order' => 'i.idate DESC',
'limit' => array( 0, $limit )
) );
$this->res = $this->ipsclass->DB->exec_query();
$this->total = $this->ipsclass->DB->get_num_rows( $this->res );
//print_r($this->ipsclass->DB);
if( $do_pull )
{
while( $r = $this->ipsclass->DB->fetch_row() )
{
$images[] = $r;
}
return $images;
}
}
}
?>