forked from GNUsocial/gnu-social
Quick function to get an array of thumbnails for a gallery page.
This commit is contained in:
parent
3da5dccce6
commit
7e8ff72c0b
@ -62,6 +62,8 @@ class GNUsocialPhotosPlugin extends Plugin
|
|||||||
$schema = Schema::get();
|
$schema = Schema::get();
|
||||||
$schema->ensureTable('GNUsocialPhoto',
|
$schema->ensureTable('GNUsocialPhoto',
|
||||||
array(new ColumnDef('notice_id', 'int(11)', null, false),
|
array(new ColumnDef('notice_id', 'int(11)', null, false),
|
||||||
|
new ColumnDef('album_id', 'int(11)', null, false),
|
||||||
|
//new ColumnDef('album_name', 'varchar(30)', null, false),
|
||||||
new ColumnDef('uri', 'varchar(512)', null, false),
|
new ColumnDef('uri', 'varchar(512)', null, false),
|
||||||
new ColumnDef('thumb_uri', 'varchar(512)', null, false)));
|
new ColumnDef('thumb_uri', 'varchar(512)', null, false)));
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,11 @@ class PhotosAction extends Action
|
|||||||
$pathparts = explode('/', $args[1]['nickname']);
|
$pathparts = explode('/', $args[1]['nickname']);
|
||||||
$username = $pathparts[0];
|
$username = $pathparts[0];
|
||||||
$this->elementStart('ul', array('class' => 'photothumbs'));
|
$this->elementStart('ul', array('class' => 'photothumbs'));
|
||||||
|
|
||||||
|
//scorbett
|
||||||
|
$photo_obj = new GNUsocialPhoto();
|
||||||
|
$photo_obj->getGalleryPage(1, 0, 9);
|
||||||
|
|
||||||
while (false !== ($file = readdir($dir))) {
|
while (false !== ($file = readdir($dir))) {
|
||||||
$fparts = explode('-', $file);
|
$fparts = explode('-', $file);
|
||||||
if ($fparts[0] == $username // uploaded by this user
|
if ($fparts[0] == $username // uploaded by this user
|
||||||
|
@ -137,7 +137,8 @@ class PhotouploadAction extends Action
|
|||||||
$uri = 'http://' . common_config('site', 'server') . '/file/' . $filename;
|
$uri = 'http://' . common_config('site', 'server') . '/file/' . $filename;
|
||||||
$thumb_uri = 'http://' . common_config('site', 'server') . '/file/thumb.' . $filename;
|
$thumb_uri = 'http://' . common_config('site', 'server') . '/file/thumb.' . $filename;
|
||||||
$profile_id = $cur->id;
|
$profile_id = $cur->id;
|
||||||
GNUsocialPhoto::saveNew($profile_id, $thumb_uri, $uri, 'web');
|
//scorbett: the second arg below should be set to the album ID
|
||||||
|
GNUsocialPhoto::saveNew($profile_id, 0, $thumb_uri, $uri, 'web');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,16 @@ class GNUsocialPhoto extends Memcached_DataObject
|
|||||||
{
|
{
|
||||||
public $__table = 'GNUsocialPhoto';
|
public $__table = 'GNUsocialPhoto';
|
||||||
public $notice_id; // int(11)
|
public $notice_id; // int(11)
|
||||||
|
public $album_id; // int(11)
|
||||||
public $uri; // varchar(512)
|
public $uri; // varchar(512)
|
||||||
public $thumb_uri; // varchar(512)
|
public $thumb_uri; // varchar(512)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* k key
|
||||||
|
* v value
|
||||||
|
*/
|
||||||
function staticGet($k,$v=NULL)
|
function staticGet($k,$v=NULL)
|
||||||
{
|
{
|
||||||
return Memcached_DataObject::staticGet('GNUsocialPhoto',$k,$v);
|
return Memcached_DataObject::staticGet('GNUsocialPhoto',$k,$v);
|
||||||
@ -58,6 +65,7 @@ class GNUsocialPhoto extends Memcached_DataObject
|
|||||||
function table()
|
function table()
|
||||||
{
|
{
|
||||||
return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
||||||
|
'album_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
||||||
'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
||||||
'thumb_uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
|
'thumb_uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
|
||||||
}
|
}
|
||||||
@ -77,11 +85,12 @@ class GNUsocialPhoto extends Memcached_DataObject
|
|||||||
return array(false, false, false);
|
return array(false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveNew($profile_id, $thumb_uri, $uri, $source)
|
function saveNew($profile_id, $album_id, $thumb_uri, $uri, $source)
|
||||||
{
|
{
|
||||||
$photo = new GNUsocialPhoto();
|
$photo = new GNUsocialPhoto();
|
||||||
$photo->thumb_uri = $thumb_uri;
|
$photo->thumb_uri = $thumb_uri;
|
||||||
$photo->uri = $uri;
|
$photo->uri = $uri;
|
||||||
|
$photo->album_id = $album_id;
|
||||||
|
|
||||||
$notice = Notice::saveNew($profile_id, $uri, $source);
|
$notice = Notice::saveNew($profile_id, $uri, $source);
|
||||||
$photo->notice_id = $notice->id;
|
$photo->notice_id = $notice->id;
|
||||||
@ -92,6 +101,28 @@ class GNUsocialPhoto extends Memcached_DataObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO: -Sanitize input
|
||||||
|
* @param int page_id The desired page of the gallery to show.
|
||||||
|
* @param int album_id The id of the album to get photos from.
|
||||||
|
* @param int gallery_size The number of thumbnails to show per page in the gallery.
|
||||||
|
* @return array Array of GNUsocialPhotos for this gallery page.
|
||||||
|
*/
|
||||||
|
function getGalleryPage($page_id, $album_id, $gallery_size)
|
||||||
|
{
|
||||||
|
$page_offset = ($page_id-1) * $gallery_size;
|
||||||
|
$sql = 'SELECT * FROM GNUsocialPhoto order by notice_id limit ' . $page_offset . ',' . $gallery_size;
|
||||||
|
$this->query($sql);
|
||||||
|
$thumbs = array();
|
||||||
|
|
||||||
|
while ($this->fetch()) {
|
||||||
|
$thumbs[] = clone($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $thumbs;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function asActivityNoun($element)
|
function asActivityNoun($element)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user