summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspider@app1 <spiderr@bitweaver.org>2016-06-17 00:12:29 -0400
committerspider@app1 <spiderr@bitweaver.org>2016-06-17 00:12:29 -0400
commit106ea56506d8a69fe209f595c111a15d45d62b2a (patch)
treef5f668935626e1320469776ba74be8274bc78925
parent3e83c3d6c48f79c1037baf4934af22200c697da6 (diff)
downloadfisheye-106ea56506d8a69fe209f595c111a15d45d62b2a.tar.gz
fisheye-106ea56506d8a69fe209f595c111a15d45d62b2a.tar.bz2
fisheye-106ea56506d8a69fe209f595c111a15d45d62b2a.zip
improve apcu object caching
-rw-r--r--FisheyeBase.php12
-rw-r--r--FisheyeGallery.php126
-rw-r--r--FisheyeImage.php11
-rw-r--r--image_lookup_inc.php4
4 files changed, 82 insertions, 71 deletions
diff --git a/FisheyeBase.php b/FisheyeBase.php
index 713b608..3054681 100644
--- a/FisheyeBase.php
+++ b/FisheyeBase.php
@@ -18,13 +18,13 @@ abstract class FisheyeBase extends LibertyMime
abstract public static function getServiceKey();
+ public function __sleep() {
+ return array_merge( parent::__sleep(), array( 'mGalleryPath' ) );
+ }
+
function __construct() {
$this->mGalleryPath = '';
- if( get_class( $this ) == 'fisheyegallery' ) {
- parent::__construct();
- } else {
- parent::__construct();
- }
+ parent::__construct();
}
// regular expression to determine if the title was computer generated
@@ -179,7 +179,7 @@ not ready for primetime
// image has been requested to be put in a new gallery
if( empty( $inGalleries[$galleryId] ) ) {
if( empty( $galleries[$galleryId] ) ) {
- $galleries[$galleryId] = new FisheyeGallery( $galleryId );
+ $galleries[$galleryId] = FisheyeGallery::lookup( array( 'gallery_id' => $galleryId ) );
$galleries[$galleryId]->load();
}
if( $galleries[$galleryId]->isValid() ) {
diff --git a/FisheyeGallery.php b/FisheyeGallery.php
index abcdd4d..6bcdcd1 100644
--- a/FisheyeGallery.php
+++ b/FisheyeGallery.php
@@ -56,6 +56,14 @@ class FisheyeGallery extends FisheyeBase {
$this->mAdminContentPerm = 'p_fisheye_admin';
}
+ public function __wakeup() {
+ return parent::__wakeup();
+ }
+
+ public function __sleep() {
+ return array_merge( parent::__sleep(), array( 'mGalleryId', 'mItems' ) );
+ }
+
function isValid() {
return( @$this->verifyId( $this->mGalleryId ) || @$this->verifyId( $this->mContentId ) );
}
@@ -75,8 +83,8 @@ class FisheyeGallery extends FisheyeBase {
$lookupContentGuid = NULL;
}
- if( BitBase::verifyId( $lookupContentId ) ) {
- $ret = LibertyBase::getLibertyObject( $lookupContentId, $lookupContentGuid );
+ if( static::verifyId( $lookupContentId ) ) {
+ $ret = parent::getLibertyObject( $lookupContentId, $lookupContentGuid );
}
return $ret;
@@ -196,75 +204,75 @@ class FisheyeGallery extends FisheyeBase {
}
}
- function loadImages( $pPage=-1, $pImagesPerPage=-1) {
+ function loadImages( $pPage=-1, $pImagesPerPage=-1, $pRefresh=FALSE ) {
global $gLibertySystem, $gBitSystem, $gBitUser;
if( !$this->isValid() ) {
return NULL;
}
- $bindVars = array($this->mContentId);
- $whereSql = $selectSql = $joinSql = $orderSql = '';
- $rowCount = $offset = NULL;
- $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
+ if( empty( $this->mItems ) || $pRefresh ) {
+ $bindVars = array($this->mContentId);
+ $whereSql = $selectSql = $joinSql = $orderSql = '';
+ $rowCount = $offset = NULL;
+ $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
- if( $gBitSystem->isFeatureActive( 'fisheye_gallery_default_sort_mode' ) ) {
- $orderSql = ", ".$this->mDb->convertSortmode( $gBitSystem->getConfig( 'fisheye_gallery_default_sort_mode' ) );
- } else {
- $orderSql = ", fgim.`item_content_id`";
- }
+ if( $gBitSystem->isFeatureActive( 'fisheye_gallery_default_sort_mode' ) ) {
+ $orderSql = ", ".$this->mDb->convertSortmode( $gBitSystem->getConfig( 'fisheye_gallery_default_sort_mode' ) );
+ } else {
+ $orderSql = ", fgim.`item_content_id`";
+ }
- // load for just a single page
- if( $pPage != -1 ) {
- if( $this->getLayout() == FISHEYE_PAGINATION_POSITION_NUMBER ) {
- $query = "SELECT DISTINCT(FLOOR(`item_position`))
- FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map`
- WHERE gallery_content_id=?
- ORDER BY floor(item_position)";
- $mantissa = $this->mDb->getOne( $query, array( $this->mContentId ), 1, ($pPage - 1) );
- // gallery image order with no positions set will have NULL mantissa, and all images will be shown
- if( !is_null( $mantissa ) ) {
- $whereSql .= " AND floor(item_position)=? ";
- array_push( $bindVars, $mantissa );
+ // load for just a single page
+ if( $pPage != -1 ) {
+ if( $this->getLayout() == FISHEYE_PAGINATION_POSITION_NUMBER ) {
+ $query = "SELECT DISTINCT(FLOOR(`item_position`))
+ FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map`
+ WHERE gallery_content_id=?
+ ORDER BY floor(item_position)";
+ $mantissa = $this->mDb->getOne( $query, array( $this->mContentId ), 1, ($pPage - 1) );
+ // gallery image order with no positions set will have NULL mantissa, and all images will be shown
+ if( !is_null( $mantissa ) ) {
+ $whereSql .= " AND floor(item_position)=? ";
+ array_push( $bindVars, $mantissa );
+ }
+ } elseif( $this->getLayout() == FISHEYE_PAGINATION_FIXED_GRID ) {
+ $rowCount = $this->getField( 'rows_per_page' ) * $this->getField( 'cols_per_page' );
+ $offset = $rowCount * ($pPage - 1);
+ } else {
+ $rowCount = $pImagesPerPage;
+ $offset = $rowCount * ($pPage - 1);
}
- } elseif( $this->getLayout() == FISHEYE_PAGINATION_FIXED_GRID ) {
- $rowCount = $this->getField( 'rows_per_page' ) * $this->getField( 'cols_per_page' );
- $offset = $rowCount * ($pPage - 1);
- } else {
- $rowCount = $pImagesPerPage;
- $offset = $rowCount * ($pPage - 1);
}
- }
- $this->mItems = array();
+ $this->mItems = array();
- $query = "SELECT fgim.*, lc.`user_id`, lct.*, ufm.`favorite_content_id` AS is_favorite $selectSql
- FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim
- INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( lc.`content_id`=fgim.`item_content_id` )
- INNER JOIN `".BIT_DB_PREFIX."liberty_content_types` lct ON ( lct.`content_type_guid`=lc.`content_type_guid` )
- $joinSql
- LEFT OUTER JOIN `".BIT_DB_PREFIX."users_favorites_map` ufm ON ( ufm.`favorite_content_id`=lc.`content_id` AND lc.`user_id`=ufm.`user_id` )
- WHERE fgim.`gallery_content_id` = ? $whereSql
- ORDER BY fgim.`item_position` $orderSql";
- $rs = $this->mDb->query($query, $bindVars, $rowCount, $offset);
+ $query = "SELECT fgim.*, lc.`user_id`, lct.*, ufm.`favorite_content_id` AS is_favorite $selectSql
+ FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim
+ INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( lc.`content_id`=fgim.`item_content_id` )
+ INNER JOIN `".BIT_DB_PREFIX."liberty_content_types` lct ON ( lct.`content_type_guid`=lc.`content_type_guid` )
+ $joinSql
+ LEFT OUTER JOIN `".BIT_DB_PREFIX."users_favorites_map` ufm ON ( ufm.`favorite_content_id`=lc.`content_id` AND lc.`user_id`=ufm.`user_id` )
+ WHERE fgim.`gallery_content_id` = ? $whereSql
+ ORDER BY fgim.`item_position` $orderSql";
+ $rs = $this->mDb->query($query, $bindVars, $rowCount, $offset);
- $rows = $rs->getRows();
- foreach ($rows as $row) {
- $pass = TRUE;
- if( $gBitSystem->isPackageActive( 'gatekeeper' ) ) {
- $pass = $gBitUser->hasPermission( 'p_fisheye_admin' ) || !@$this->verifyId( $row['security_id'] ) || ( $row['user_id'] == $gBitUser->mUserId ) || @$this->verifyId( $_SESSION['gatekeeper_security'][$row['security_id']] );
- }
- if( $pass ) {
- $type = $gLibertySystem->mContentTypes[$row['content_type_guid']];
- require_once( constant( strtoupper( $type['handler_package'] ).'_PKG_PATH' ).$type['handler_file'] );
- $item = new $type['handler_class']( NULL, $row['item_content_id'] );
- if( is_object( $item ) && $item->load() ) {
- $item->loadThumbnail( $this->mInfo['thumbnail_size'] );
- $item->setGalleryPath( $this->mGalleryPath.'/'.$this->mGalleryId );
- $item->mInfo['item_position'] = $row['item_position'];
- $this->mItems[$row['item_content_id']] = $item;
+ $rows = $rs->getRows();
+ foreach ($rows as $row) {
+ $pass = TRUE;
+ if( $gBitSystem->isPackageActive( 'gatekeeper' ) ) {
+ $pass = $gBitUser->hasPermission( 'p_fisheye_admin' ) || !@$this->verifyId( $row['security_id'] ) || ( $row['user_id'] == $gBitUser->mUserId ) || @$this->verifyId( $_SESSION['gatekeeper_security'][$row['security_id']] );
+ }
+ if( $pass ) {
+ $type = $gLibertySystem->mContentTypes[$row['content_type_guid']];
+ require_once( constant( strtoupper( $type['handler_package'] ).'_PKG_PATH' ).$type['handler_file'] );
+ if( $item = parent::getLibertyObject( $row['item_content_id'], $row['content_type_guid'] ) ) {
+ $item->loadThumbnail( $this->mInfo['thumbnail_size'] );
+ $item->setGalleryPath( $this->mGalleryPath.'/'.$this->mGalleryId );
+ $item->mInfo['item_position'] = $row['item_position'];
+ $this->mItems[$row['item_content_id']] = $item;
+ }
}
}
}
-
return count( $this->mItems );
}
@@ -462,7 +470,7 @@ class FisheyeGallery extends FisheyeBase {
}
if( @$this->verifyId( $pThumbnailContentId ) ) {
- $ret = LibertyBase::getLibertyObject( $pThumbnailContentId, $pThumbnailContentType );
+ $ret = parent::getLibertyObject( $pThumbnailContentId, $pThumbnailContentType );
if( is_a( $ret, 'FisheyeGallery' ) ) {
//recurse down in to find the first image
if( $ret = $ret->getThumbnailImage() ) {
@@ -1093,7 +1101,7 @@ class FisheyeGallery extends FisheyeBase {
function addGalleryRecursive( $pGalleryId , $pPath = '/', &$pZip ){
- $gallery = new FisheyeGallery($pGalleryId);
+ $gallery = FisheyeGallery::lookup( array( 'galley_id' => $pGalleryId ) );
$gallery->load();
$gallery->loadImages();
$pPath .= $gallery->getTitle().'/';
diff --git a/FisheyeImage.php b/FisheyeImage.php
index 988e926..b85683d 100644
--- a/FisheyeImage.php
+++ b/FisheyeImage.php
@@ -38,8 +38,13 @@ class FisheyeImage extends FisheyeBase {
$this->mAdminContentPerm = 'p_fisheye_admin';
}
+ public function __wakeup() {
+ return parent::__wakeup();
+ }
+
public function __sleep() {
- return array_merge( parent::__sleep(), array( 'mImageId' ) );
+ $ret = array_merge( parent::__sleep(), array( 'mImageId' ) );
+ return $ret;
}
public static function lookup( $pLookupHash ) {
@@ -57,8 +62,8 @@ class FisheyeImage extends FisheyeBase {
$lookupContentGuid = NULL;
}
- if( BitBase::verifyId( $lookupContentId ) ) {
- $ret = LibertyBase::getLibertyObject( $lookupContentId, $lookupContentGuid );
+ if( static::verifyId( $lookupContentId ) ) {
+ $ret = static::getLibertyObject( $lookupContentId, $lookupContentGuid );
}
return $ret;
diff --git a/image_lookup_inc.php b/image_lookup_inc.php
index 0dabeaf..8de4b0e 100644
--- a/image_lookup_inc.php
+++ b/image_lookup_inc.php
@@ -31,9 +31,7 @@ if( empty( $_REQUEST['gallery_id'] ) ) {
}
// the image is considered the primary content, however the gallery is useful
if( !empty($_REQUEST['gallery_id']) && is_numeric($_REQUEST['gallery_id']) ) {
- $gGallery = new FisheyeGallery( $_REQUEST['gallery_id'], NULL, FALSE );
- $gGallery->load();
- $gGallery->loadCurrentImage( $gContent->mImageId );
+ $gGallery = FisheyeGallery::lookup( $_REQUEST );
$gBitSmarty->assignByRef('gGallery', $gGallery);
$gBitSmarty->assignByRef('galleryId', $_REQUEST['gallery_id']);
}