diff options
| author | lsces <lester@lsces.co.uk> | 2025-08-28 16:20:37 +0100 |
|---|---|---|
| committer | lsces <lester@lsces.co.uk> | 2025-08-28 16:20:37 +0100 |
| commit | 7a981e40e60ac07b2e57932d6434dfb7ee7b5fb4 (patch) | |
| tree | 188a33dfb5607387dbd058f6364019b6ed4bf172 /includes | |
| parent | 2140176e21e83d3779460277a31bcc7adaf9d3fe (diff) | |
| download | fisheye-7a981e40e60ac07b2e57932d6434dfb7ee7b5fb4.tar.gz fisheye-7a981e40e60ac07b2e57932d6434dfb7ee7b5fb4.tar.bz2 fisheye-7a981e40e60ac07b2e57932d6434dfb7ee7b5fb4.zip | |
Classes code updated to PHP8.4 and namespace ... work in progress on updating some third party code
Diffstat (limited to 'includes')
| -rwxr-xr-x[-rw-r--r--] | includes/classes/FisheyeBase.php | 140 | ||||
| -rwxr-xr-x[-rw-r--r--] | includes/classes/FisheyeGallery.php | 434 | ||||
| -rwxr-xr-x[-rw-r--r--] | includes/classes/FisheyeImage.php | 321 | ||||
| -rwxr-xr-x[-rw-r--r--] | includes/classes/FisheyeRemote.php | 114 |
4 files changed, 526 insertions, 483 deletions
diff --git a/includes/classes/FisheyeBase.php b/includes/classes/FisheyeBase.php index d0f3c88..a2d45da 100644..100755 --- a/includes/classes/FisheyeBase.php +++ b/includes/classes/FisheyeBase.php @@ -6,55 +6,91 @@ /** * required setup */ -require_once( LIBERTY_PKG_CLASS_PATH.'LibertyMime.php' ); // FisheyeGallery base class +namespace Bitweaver\Fisheye; +use Bitweaver\Liberty\LibertyMime; // FisheyeGallery base class +use Bitweaver\Liberty\LibertyContent; + +define('FISHEYEGALLERY_CONTENT_TYPE_GUID', 'fisheyegallery' ); /** * @package fisheye */ +#[\AllowDynamicProperties] abstract class FisheyeBase extends LibertyMime { // Path of gallery images to get breadcrumbs public $mGalleryPath; + public $mGalleryId; abstract public static function getServiceKey(); public function __sleep() { - return array_merge( parent::__sleep(), array( 'mGalleryPath' ) ); + return array_merge( parent::__sleep(), [ 'mGalleryPath' ] ); } - function __construct() { + public function __construct() { $this->mGalleryPath = ''; parent::__construct(); } // regular expression to determine if the title was computer generated - function isMachineName( $pString ) { - return( preg_match( '/(^[0-9][-0-9 ]*$)|(^[-0-9 ]*(img|dsc|dscn|pict|htg|dscf|p)[-0-9 ][-0-9 ]*.*$)/i', trim( $pString ) ) ); + public function isMachineName( $pString ) { + if ( !empty($pString) ) { + return preg_match( '/(^[0-9][-0-9 ]*$)|(^[-0-9 ]*(img|dsc|dscn|pict|htg|dscf|p)[-0-9 ][-0-9 ]*.*$)/i', trim( $pString ) ); + } else { + return ''; + } } // Gets a list of galleries which this item is attached to - function getParentGalleries( $pContentId=NULL ) { + public function getParentGalleries( $pContentId=null ) { if( !$this->verifyId( $pContentId ) ) { $pContentId = $this->mContentId; } - $ret = NULL; + $ret = null; if( is_numeric( $pContentId ) ) { $sql = "SELECT fg.`gallery_id` AS `hash_key`, fg.*, lc.`title` FROM `".BIT_DB_PREFIX."fisheye_gallery` fg, `".BIT_DB_PREFIX."liberty_content` lc, `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim WHERE fgim.`item_content_id` = ? AND fgim.`gallery_content_id`=fg.`content_id` AND fg.`content_id`=lc.`content_id`"; - $ret = $this->mDb->getAssoc( $sql, array( $pContentId ) ); + $ret = $this->mDb->getAssoc( $sql, [ $pContentId ] ); + } + if ( $ret ) { + $parents = current( $ret ); + $sql = "WITH TREE AS + ( SELECT fgim.`item_content_id` AS gallery_content_id, + LAG( fgim.`item_content_id`) OVER (ORDER BY fgim.`item_position`) AS PREVIOUS, + LEAD( fgim.`item_content_id` ) OVER (ORDER BY fgim.`item_position`) AS NEXT + FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim + WHERE fgim.`gallery_content_id` = ? + order by fgim.`item_position` ) + SELECT pr.PREVIOUS, prec.`content_type_guid` AS PRE_T, pr.NEXT, posc.`content_type_guid` AS NEXT_T FROM TREE pr + LEFT JOIN `".BIT_DB_PREFIX."liberty_content` prec ON prec.`content_id` = pr.PREVIOUS + LEFT JOIN `".BIT_DB_PREFIX."liberty_content` posc ON posc.`content_id` = pr.NEXT + WHERE pr.`gallery_content_id` = ?"; + if( $parents = $this->mDb->getRow($sql, [ $parents['content_id'], $pContentId ] ) ) { + if ( $parents['pre_t'] == FISHEYEGALLERY_CONTENT_TYPE_GUID ) { + $ret['previous_gallery_id'] = $parents['previous']; + } else { + $ret['previous_image_id'] = $parents['previous']; + } + if ( $parents['next_t'] == FISHEYEGALLERY_CONTENT_TYPE_GUID ) { + $ret['next_gallery_id'] = $parents['next']; + }else { + $ret['next_image_id'] = $parents['previous']; + } + } } return $ret; } - function loadParentGalleries() { + public function loadParentGalleries() { if( $this->isValid() ) { $this->mInfo['parent_galleries'] = $this->getParentGalleries(); } } - function updatePosition($pGalleryContentId, $newPosition = NULL) { + public function updatePosition($pGalleryContentId, $newPosition = null) { if( $pGalleryContentId && $newPosition && $this->verifyId($this->mContentId) ) { // SQL optimization to prevent stupid updates of identical data if( $radixPosition = strpos( $newPosition, '.' ) ) { @@ -65,40 +101,40 @@ abstract class FisheyeBase extends LibertyMime } $cleanPosition = preg_replace( '/\./', '', $newPosition ); $sql = "UPDATE `".BIT_DB_PREFIX."fisheye_gallery_image_map` SET `item_position` = ? - WHERE `item_content_id` = ? AND `gallery_content_id` = ? AND (`item_position` IS NULL OR `item_position`!=?)"; - $rs = $this->mDb->query($sql, array($newPosition, $this->mContentId, $pGalleryContentId, $newPosition)); + WHERE `item_content_id` = ? AND `gallery_content_id` = ? AND (`item_position` IS null OR `item_position`!=?)"; + $rs = $this->mDb->getOne($sql, [ $newPosition, $this->mContentId, $pGalleryContentId, $newPosition ] ); } } - function setGalleryPath( $pPath ) { + public function setGalleryPath( $pPath ) { $this->setField( 'gallery_path', rtrim( $pPath, '/' ) ); } - function getThumbnailContentId() { + public function getThumbnailContentId() { // PURE VIRTUAL } - function loadThumbnail( $pSize='small', $pContentId=NULL ) { + public function loadThumbnail( $pSize='small', $pContentId=null ) { // Default does nothing } - // Possible derived read-only object such as Facebook, Instagram, etc.. default is TRUE - function isEditable() { - return TRUE; + // Possible derived read-only object such as Facebook, Instagram, etc.. default is true + public function isEditable() { + return true; } // THis is a function that creates a mack daddy function to get a breadcrumb path with a single query. // Do not muck with this query unless you really, truly understand what is going on. /* not ready for primetime - function getPaths() { + public function getPaths() { global $gBitDb; - $ret = NULL; + $ret = null; if( $this->isValid() ) { if( $this->mDb->isAdvancedPostgresEnabled() ) { - $bindVars = array(); - $containVars = array(); + $bindVars = []; + $containVars = []; $selectSql = ''; $joinSql = ''; $whereSql = ''; @@ -108,7 +144,7 @@ not ready for primetime INNER JOIN `".BIT_DB_PREFIX."fisheye_gallery` fg ON (fg.`content_id`=cb_item_content_id) INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON(lc.`content_id`=fg.`content_id`) ORDER BY level DESC, branch, lc.`title`"; - if( $ret = $gBitDb->GetAssoc( $query, array( $this->mContentId ) ) ) { + if( $ret = $gBitDb->GetAssoc( $query, [ $this->mContentId ] ) ) { } } } @@ -116,10 +152,10 @@ not ready for primetime } */ - function getBreadcrumbLinks( $pIncludeSelf = FALSE ) { + public function getBreadcrumbLinks( $pIncludeSelf = false ) { global $gBitSystem; //$ret['fisheye'] = $gBitSystem->getConfig('site_title'); - $ret = array(); + $ret = []; if( !$this->getField( 'gallery_path' ) ) { if( $this->isValid() && $parents = $this->getParentGalleries() ) { $gal = current( $parents ); @@ -133,9 +169,9 @@ not ready for primetime $joinSql = ''; $selectSql = '';//AS title$g, fg$g.gallery_id AS gallery_id$g"; $whereSql = ''; - $bindVars = array(); + $bindVars = []; // We need to get min_content_status_id - $pListHash = array(); + $pListHash = []; LibertyContent::prepGetList($pListHash); foreach( $path as $galleryId ) { if( $galleryId ) { @@ -154,10 +190,10 @@ not ready for primetime INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc$c ON(fgim$c.`item_content_id`=lc$c.`content_id`) "; $whereSql .= " lc$c.`content_id`=? AND fgim$c.`gallery_content_id`=lc$p.`content_id` "; array_push( $bindVars, $this->mContentId ); - $rs = $this->mDb->query( "SELECT ".rtrim( $selectSql, ',')." FROM ".rtrim( $joinSql, ',')." WHERE $whereSql", $bindVars ); - if( !empty( $rs->fields ) ) { - for( $i = 1; $i <= (count( $rs->fields ) / 2); $i++ ) { - $ret[$rs->fields['gallery_id'.$i]] = $rs->fields['title'.$i]; + $rs = $this->mDb->getRow( "SELECT ".rtrim( $selectSql, ',')." FROM ".rtrim( $joinSql, ',')." WHERE $whereSql", $bindVars ); + if( !empty( $rs ) ) { + for( $i = 1; $i <= (count( $rs ) / 2); $i++ ) { + $ret[$rs['gallery_id'.$i]] = $rs['title'.$i]; } } } @@ -170,38 +206,38 @@ not ready for primetime } - function addToGalleries( $pGalleryArray ) { + public function addToGalleries( $pGalleryArray ) { global $gBitSystem; if( $this->isValid() ) { - $inGalleries = $this->mDb->getAssoc( "SELECT `gallery_id`,`gallery_content_id` FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim INNER JOIN `".BIT_DB_PREFIX."fisheye_gallery` fg ON (fgim.`gallery_content_id`=fg.`content_id`) WHERE `item_content_id` = ?", array( $this->mContentId ) ); - $galleries = array(); + $inGalleries = $this->mDb->getAssoc( "SELECT `gallery_id`,`gallery_content_id` FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim INNER JOIN `".BIT_DB_PREFIX."fisheye_gallery` fg ON (fgim.`gallery_content_id`=fg.`content_id`) WHERE `item_content_id` = ?", [ $this->mContentId ] ); + $galleries = []; if( is_array( $pGalleryArray ) && count( $pGalleryArray ) ) { foreach( $pGalleryArray as $galleryId ) { // image has been requested to be put in a new gallery if( !is_numeric( $galleryId ) ) { switch( $galleryId ) { case 'newest': - $galleryId = $this->mDb->getAssoc( "SELECT `gallery_id` FROM `".BIT_DB_PREFIX."fisheye_gallery` fg INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (fg.`content_id`=lg.`content_id`) WHERE `user_id` = ? ORDER BY gallery_id DESC", array( $this->getField( 'user_id' ) ) ); + $galleryId = $this->mDb->getAssoc( "SELECT `gallery_id` FROM `".BIT_DB_PREFIX."fisheye_gallery` fg INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (fg.`content_id`=lg.`content_id`) WHERE `user_id` = ? ORDER BY gallery_id DESC", [ $this->getField( 'user_id' ) ] ); break; } } if( empty( $inGalleries[$galleryId] ) ) { if( empty( $galleries[$galleryId] ) ) { - if( $galleries[$galleryId] = FisheyeGallery::lookup( array( 'gallery_id' => $galleryId ) ) ) { + if( $galleries[$galleryId] = FisheyeGallery::lookup( [ 'gallery_id' => $galleryId ] ) ) { $galleries[$galleryId]->load(); } } if( $galleries[$galleryId] && $galleries[$galleryId]->isValid() ) { - if( $galleries[$galleryId]->hasUserPermission( 'p_fisheye_upload', TRUE, FALSE ) || $galleries[$galleryId]->isPublic() ) { + if( $galleries[$galleryId]->hasUserPermission( 'p_fisheye_upload', true, false ) || $galleries[$galleryId]->isPublic() ) { if( $gBitSystem->isFeatureActive( 'fisheye_gallery_default_sort_mode' ) ) { - $pos = NULL; + $pos = null; } else { $query = "SELECT MAX(`item_position`) FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim INNER JOIN `".BIT_DB_PREFIX."fisheye_gallery` fg ON(fgim.`gallery_content_id`=fg.`content_id`) WHERE fg.`gallery_id`=?"; - $pos = $this->mDb->getOne( $query, array( $galleryId ) ) + 10; + $pos = $this->mDb->getOne( $query, [ $galleryId ] ) + 10; } $galleries[$galleryId]->addItem( $this->mContentId, $pos ); @@ -219,50 +255,50 @@ not ready for primetime // if we have any left over in the inGalleries array, we should delete them. these were the "unchecked" boxes foreach( $inGalleries as $galleryId ) { $sql = "DELETE FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE `gallery_content_id` = ? AND `item_content_id` = ?"; - $rs = $this->mDb->query($sql, array( $galleryId, $this->mContentId ) ); + $rs = $this->mDb->getOne($sql, [ $galleryId, $this->mContentId ] ); } } } } - function isPublic() { + public function isPublic() { if( $this->isValid() ) { - return ( $this->getPreference( 'is_public' ) == 'y' ); + return $this->getPreference( 'is_public' ) == 'y'; } + return false; } - function isInGallery( $pGalleryContentId, $pItemContentId = NULL) { + public function isInGallery( $pGalleryContentId, $pItemContentId = null) { if( !$this->verifyId( $pItemContentId ) ) { $pItemContentId = $this->mContentId; } - $ret = FALSE; + $ret = false; if ( is_numeric( $this->mGalleryId ) && is_numeric( $pGalleryContentId ) ) { if( $this->mDb->isAdvancedPostgresEnabled() ) { global $gBitDb, $gBitSmarty; // This code pulls all branches for the current node and determines if there is a path from this content to the root - // without hitting a security_id. If there is clear path it returns TRUE. If there is a security_id, then + // without hitting a security_id. If there is clear path it returns true. If there is a security_id, then // it determines if the current user has permission $query = "SELECT branch,level,cb_item_content_id,cb_gallery_content_id FROM connectby('`".BIT_DB_PREFIX."fisheye_gallery_image_map`', '`gallery_content_id`', '`item_content_id`', ?, 0, '/') AS t(`cb_gallery_content_id` int,`cb_item_content_id` int, `level` int, `branch` text) WHERE `cb_gallery_content_id`=? ORDER BY branch "; - if ( $this->mDb->getOne($query, array( $pItemContentId, $pGalleryContentId ) ) ) { - $ret = TRUE; + if ( $this->mDb->getOne($query, [ $pItemContentId, $pGalleryContentId ] ) ) { + $ret = true; } } else { $sql = "SELECT count(`item_content_id`) as `item_count` FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE `gallery_content_id` = ? AND `item_content_id` = ?"; - $rs = $this->mDb->query($sql, array($pGalleryContentId, $pItemContentId)); - if ($rs->fields['item_count'] > 0) { - $ret = TRUE; + $rs = $this->mDb->getRow($sql, [ $pGalleryContentId, $pItemContentId ] ); + if ($rs['item_count'] > 0) { + $ret = true; } } } return $ret; } -} -?> +}
\ No newline at end of file diff --git a/includes/classes/FisheyeGallery.php b/includes/classes/FisheyeGallery.php index 745b50a..b96cd74 100644..100755 --- a/includes/classes/FisheyeGallery.php +++ b/includes/classes/FisheyeGallery.php @@ -6,9 +6,10 @@ /** * required setup */ -require_once( FISHEYE_PKG_CLASS_PATH.'FisheyeImage.php' ); // A gallery is composed of FisheyeImages - -define('FISHEYEGALLERY_CONTENT_TYPE_GUID', 'fisheyegallery' ); +namespace Bitweaver\Fisheye; +use Bitweaver\BitBase; +use Bitweaver\KernelTools; +use Bitweaver\Liberty\LibertyContent; define( 'FISHEYE_PAGINATION_FIXED_GRID', 'fixed_grid' ); define( 'FISHEYE_PAGINATION_AUTO_FLOW', 'auto_flow' ); @@ -22,11 +23,15 @@ define( 'FISHEYE_PAGINATION_GALLERIFFIC', 'galleriffic' ); * * @package fisheye */ +#[\AllowDynamicProperties] class FisheyeGallery extends FisheyeBase { public $mGalleryId; // fisheye_gallery.gallery_id public $mItems; // Array of FisheyeImage class instances which belong to this gallery + public $mPaginationLookup; + public $mPreviewImage; + public $pRecursiveDelete; - function __construct($pGalleryId = NULL, $pContentId = NULL) { + public function __construct($pGalleryId = null, $pContentId = null) { parent::__construct(); if( $this->verifyId( $pGalleryId ) ) { $this->mGalleryId = (int)$pGalleryId; // Set member variables according to the parameters we were passed @@ -34,20 +39,21 @@ class FisheyeGallery extends FisheyeBase { if( $this->verifyId( $pContentId ) ) { $this->mContentId = (int)$pContentId; // liberty_content.content_id which this gallery references } - $this->mItems = array(); // Assume no images (if $pAutoLoad is TRUE we will populate this array later) + $this->mItems = []; // Assume no images (if $pAutoLoad is true we will populate this array later) $this->mAdminContentPerm = 'p_fisheye_admin'; // This registers the content type for FishEye galleries // FYI: Any class which uses a table which inherits from liberty_content should create their own content type(s) $this->registerContentType( - FISHEYEGALLERY_CONTENT_TYPE_GUID, array( 'content_type_guid' => FISHEYEGALLERY_CONTENT_TYPE_GUID, + FISHEYEGALLERY_CONTENT_TYPE_GUID, [ + 'content_type_guid' => FISHEYEGALLERY_CONTENT_TYPE_GUID, 'content_name' => 'Image Gallery', 'content_name_plural' => 'Image Galleries', 'handler_class' => 'FisheyeGallery', 'handler_package' => 'fisheye', 'handler_file' => 'FisheyeGallery.php', 'maintainer_url' => 'http://www.bitweaver.org' - )); + ] ); // Permission setup $this->mViewContentPerm = 'p_fisheye_view'; @@ -61,26 +67,26 @@ class FisheyeGallery extends FisheyeBase { } public function __sleep() { - return array_merge( parent::__sleep(), array( 'mGalleryId' ) ); + return array_merge( parent::__sleep(), [ 'mGalleryId' ] ); } - function isValid() { - return( @$this->verifyId( $this->mGalleryId ) || @$this->verifyId( $this->mContentId ) ); + public function isValid() { + return @$this->verifyId( $this->mGalleryId ) || @$this->verifyId( $this->mContentId ); } - public static function lookup( $pLookupHash, $pLoadFromCache=TRUE ) { + public static function lookup( $pLookupHash, $pLoadFromCache=true ) { global $gBitDb; - $ret = NULL; + $ret = null; - $lookupContentId = NULL; + $lookupContentId = null; if (!empty($pLookupHash['gallery_id']) && is_numeric($pLookupHash['gallery_id'])) { - if( $lookup = $gBitDb->getRow( "SELECT lc.`content_id`, lc.`content_type_guid` FROM `".BIT_DB_PREFIX."fisheye_gallery` fg INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON(lc.`content_id`=fg.`content_id`) WHERE `gallery_id`=?", array( $pLookupHash['gallery_id'] ) ) ) { - $lookupContentId = $lookup['content_id']; + if( $lookup = $gBitDb->getRow( "SELECT lc.`content_id`, lc.`content_type_guid` FROM `".BIT_DB_PREFIX."fisheye_gallery` fg INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON(lc.`content_id`=fg.`content_id`) WHERE `gallery_id`=?", [ $pLookupHash['gallery_id'] ] ) ) { + $lookupContentId = $lookup['content_id']; $lookupContentGuid = $lookup['content_type_guid']; } } elseif (!empty($pLookupHash['content_id']) && is_numeric($pLookupHash['content_id'])) { $lookupContentId = $pLookupHash['content_id']; - $lookupContentGuid = NULL; + $lookupContentGuid = null; } if( static::verifyId( $lookupContentId ) ) { @@ -90,19 +96,19 @@ class FisheyeGallery extends FisheyeBase { return $ret; } - function load( $pContentId = NULL, $pPluginParams = NULL ) { + public function load( $pContentId = null, $pPluginParams = null ) { global $gBitSystem; - $bindVars = array(); + $bindVars = []; $selectSql = $joinSql = $whereSql = ''; - - if( @$this->verifyId( $this->mGalleryId ) ) { + + if( $this->verifyId( $this->mGalleryId ) ) { $whereSql = " WHERE fg.`gallery_id` = ?"; - $bindVars = array( $this->mGalleryId ); - } elseif ( @$this->verifyId( $this->mContentId ) ) { + $bindVars = [ $this->mGalleryId ]; + } elseif ( $this->verifyId( $this->mContentId ) ) { $whereSql = " WHERE fg.`content_id` = ?"; - $bindVars = array($this->mContentId); + $bindVars = [ $this->mContentId ]; } else { - $whereSql = NULL; + $whereSql = null; } if ($whereSql) { // If we have some way to know what fisheye_gallery row to load... @@ -116,23 +122,22 @@ class FisheyeGallery extends FisheyeBase { LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON (uue.`user_id` = lc.`modifier_user_id`) LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON (uuc.`user_id` = lc.`user_id`) $whereSql"; - - if( $rowHash = $this->mDb->GetRow($query, $bindVars) ) { - $this->mInfo = $rowHash; - $this->mContentId = $rowHash['content_id']; - + $rs = $this->mDb->getRow($query, $bindVars); + if( !empty($rs) ) { + $this->mInfo = $rs; + $this->mContentId = $rs['content_id']; LibertyContent::load(); if( @$this->verifyId($this->mInfo['gallery_id'] ) ) { $this->mGalleryId = $this->mInfo['gallery_id']; $this->mContentId = $this->mInfo['content_id']; - $this->mInfo['creator'] = (isset( $rowHash['creator_real_name'] ) ? $rowHash['creator_real_name'] : $rowHash['creator_user'] ); - $this->mInfo['editor'] = (isset( $rowHash['modifier_real_name'] ) ? $rowHash['modifier_real_name'] : $rowHash['modifier_user'] ); + $this->mInfo['creator'] = isset( $rs['creator_real_name'] ) ? $rs['creator_real_name'] : $rs['creator_user']; + $this->mInfo['editor'] = isset( $rs['modifier_real_name'] ) ? $rs['modifier_real_name'] : $rs['modifier_user']; // Set some basic defaults for how to display a gallery if they're not already set if (empty($this->mInfo['thumbnail_size'])) { - $this->mInfo['thumbnail_size'] = $this->getPreference( 'fisheye_gallery_default_thumbnail_size', NULL ); + $this->mInfo['thumbnail_size'] = $this->getPreference( 'fisheye_gallery_default_thumbnail_size', null ); } if (empty($this->mInfo['rows_per_page'])) { $this->mInfo['rows_per_page'] = $this->getPreference('fisheye_gallery_default_rows_per_page', FISHEYE_DEFAULT_ROWS_PER_PAGE); @@ -149,24 +154,23 @@ class FisheyeGallery extends FisheyeBase { $this->mInfo['num_images'] = $this->getImageCount(); if( $this->getPreference( 'gallery_pagination' ) == FISHEYE_PAGINATION_POSITION_NUMBER ) { - $this->mInfo['num_pages'] = $this->mDb->getOne( "SELECT COUNT( distinct( floor(`item_position`) ) ) FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE gallery_content_id=?", array( $this->mContentId ) ); + $this->mInfo['num_pages'] = $this->mDb->getOne( "SELECT COUNT( distinct( floor(`item_position`) ) ) FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE gallery_content_id=?", [ $this->mContentId ] ); } else { - $this->mInfo['images_per_page'] = ($this->mInfo['cols_per_page'] * $this->mInfo['rows_per_page']); - $this->mInfo['num_pages'] = (int)($this->mInfo['num_images'] / $this->mInfo['images_per_page'] + ($this->mInfo['num_images'] % $this->mInfo['images_per_page'] == 0 ? 0 : 1)); + $this->mInfo['images_per_page'] = $this->mInfo['cols_per_page'] * $this->mInfo['rows_per_page']; + $this->mInfo['num_pages'] = (int)$this->mInfo['num_images'] / $this->mInfo['images_per_page'] + ($this->mInfo['num_images'] % $this->mInfo['images_per_page'] == 0 ? 0 : 1); } } else { unset( $this->mContentId ); unset( $this->mGalleryId ); } - } } return !empty( $this->mInfo ); } - function loadCurrentImage( $pCurrentImageId ) { + public function loadCurrentImage( $pCurrentImageId ) { if( $this->isValid() && @$this->verifyId( $pCurrentImageId ) ) { // this code sucks but works - XOXO spiderr $query = "SELECT fgim.*, fi.`image_id`, lf.`file_name`, lf.`user_id`, lf.`mime_type`, la.`attachment_id` @@ -176,28 +180,27 @@ class FisheyeGallery extends FisheyeBase { INNER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON ( lf.`file_id`=la.`foreign_id` ) WHERE fgim.`gallery_content_id` = ? ORDER BY fgim.`item_position`, fi.`content_id` "; - if( $rs = $this->mDb->query($query, array( $this->mContentId ) ) ) { + if( $rows = $this->mDb->getAssoc($query, [ $this->mContentId ] ) ) { $tempImage = new FisheyeImage(); - $rows = $rs->getRows(); for( $i = 0; $i < count( $rows ); $i++ ) { if( $rows[$i]['image_id'] == $pCurrentImageId ) { if( $i > 0 ) { $this->mInfo['previous_image_id'] = $rows[$i-1]['image_id']; - $this->mInfo['previous_image_avatar'] = liberty_fetch_thumbnail_url( array( + $this->mInfo['previous_image_avatar'] = \Bitweaver\Liberty\liberty_fetch_thumbnail_url( [ 'file_name' => $rows[$i-1]['file_name'], 'source_file' => $tempImage->getSourceFile( $rows[$i-1] ), - 'mime_image' => TRUE, + 'mime_image' => true, 'size' => 'avatar', - )); + ] ); } if( $i + 1 < count( $rows ) ) { $this->mInfo['next_image_id'] = $rows[$i+1]['image_id']; - $this->mInfo['next_image_avatar'] = liberty_fetch_thumbnail_url( array( + $this->mInfo['next_image_avatar'] = \Bitweaver\Liberty\liberty_fetch_thumbnail_url( [ 'file_name' => $rows[$i+1]['file_name'], 'source_file' => $tempImage->getSourceFile( $rows[$i+1] ), - 'mime_image' => TRUE, + 'mime_image' => true, 'size' => 'avatar', - )); + ] ); } } } @@ -205,46 +208,49 @@ class FisheyeGallery extends FisheyeBase { } } - public function loadImages( $pPage=-1, $pImagesPerPage=-1, $pRefresh=FALSE ) { + public function loadImages( &$pListHash = [] ) { global $gLibertySystem, $gBitSystem, $gBitUser; if( !$this->isValid() ) { - return NULL; + return null; } - if( empty( $this->mItems ) || $pRefresh ) { - $bindVars = array($this->mContentId); + + $pListHash['cant'] = $this->mInfo['num_images']; + LibertyContent::prepGetList( $pListHash ); + + if( empty( $this->mItems ) || !empty( $pListHash['refresh'] ) ) { + $bindVars = [ $this->mContentId ]; $whereSql = $selectSql = $joinSql = $orderSql = ''; - $rowCount = $offset = NULL; + $offset = $pListHash['offset']; + $rowCount = 0; $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`"; - } - + $orderSql = $gBitSystem->isFeatureActive( 'fisheye_gallery_default_sort_mode' ) + ? ", ".$this->mDb->convertSortmode( $gBitSystem->getConfig( 'fisheye_gallery_default_sort_mode' ) ) + : ", fgim.`item_content_id`"; + // load for just a single page - if( $pPage != -1 ) { + if( $pListHash['page'] != -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 + $mantissa = $this->mDb->getOne( $query, [ $this->mContentId ], 1, $pListHash['page'] - 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); + $rowCount = ($pListHash['rows_per_page'] ?? 3) * ($pListHash['cols_per_page'] ?? 3); + $offset = $rowCount * ($pListHash['page'] - 1); } else { - $rowCount = $pImagesPerPage; - $offset = $rowCount * ($pPage - 1); + $rowCount = $pListHash['max_records']; + $offset = $rowCount * ($pListHash['page'] - 1); } } - - $this->mItems = array(); + if( empty($rowCount) ) $rowCount = $pListHash['max_records'] ?? 10; + $this->mItems = []; $query = "SELECT fgim.*, lc.`user_id`, lct.*, ufm.`favorite_content_id` AS is_favorite $selectSql FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim @@ -254,16 +260,15 @@ class FisheyeGallery extends FisheyeBase { 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; + $rows = $this->mDb->query($query, $bindVars, $rowCount, $offset); + 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 ) { if( $item = parent::getLibertyObject( $row['item_content_id'], $row['content_type_guid'], $this->isCacheableObject() ) ) { - $item->loadThumbnail( $this->mInfo['thumbnail_size'] ); + $item->loadThumbnail( $this->mInfo['thumbnail_size'] ?? 'small' ); $item->setGalleryPath( $this->mGalleryPath.'/'.$this->mGalleryId ); $item->mInfo['item_position'] = $row['item_position']; $this->mItems[$row['item_content_id']] = $item; @@ -271,25 +276,26 @@ class FisheyeGallery extends FisheyeBase { } } } - return count( $this->mItems ); + + LibertyContent::postGetList( $pListHash ); + + return count ( $this->mItems ) > 0; } - function getImageList() { + public function getImageList() { global $gLibertySystem, $gBitSystem, $gBitUser; - $ret = NULL; + $ret = null; if( $this->isValid() ) { - $bindVars = array($this->mContentId); + $bindVars = [ $this->mContentId ]; $whereSql = $selectSql = $joinSql = $orderSql = ''; - $rows = $offset = NULL; + $rows = $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`"; - } + $orderSql = $gBitSystem->isFeatureActive( 'fisheye_gallery_default_sort_mode' ) + ? ", ".$this->mDb->convertSortmode( $gBitSystem->getConfig( 'fisheye_gallery_default_sort_mode' ) ) + : ", fgim.`item_content_id`"; - $this->mItems = array(); + $this->mItems = []; $query = "SELECT lc.`content_id` AS `has_key`, fgim.*, lc.*, lct.*, fi.`image_id`, ufm.`favorite_content_id` AS is_favorite $selectSql FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim @@ -305,7 +311,7 @@ class FisheyeGallery extends FisheyeBase { return $ret; } - function exportHash( $pPaginate = FALSE ) { + public function exportHash( $pPaginate = false ) { if( $ret = parent::exportHash() ) { $ret['type'] = $this->getContentType(); if( $this->loadImages() ) { @@ -323,10 +329,10 @@ class FisheyeGallery extends FisheyeBase { return $ret; } - function getItemPage( $pItemContentId ) { - $ret = NULL; + public function getItemPage( $pItemContentId ) { + $ret = null; if( empty( $this->mPaginationLookup ) ) { - $this->mPaginationLookup = $this->mDb->getAssoc( "SELECT `item_content_id`, floor(`item_position`) FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE `gallery_content_id`=?", array( $this->mContentId ) ); + $this->mPaginationLookup = $this->mDb->getAssoc( "SELECT `item_content_id`, floor(`item_position`) FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE `gallery_content_id`=?", [ $this->mContentId ] ); } if( !empty( $this->mPaginationLookup[$pItemContentId] ) ) { $ret = $this->mPaginationLookup[$pItemContentId]; @@ -334,8 +340,8 @@ class FisheyeGallery extends FisheyeBase { return $ret; } - function getPreviewHash() { - $ret = array(); + public function getPreviewHash() { + $ret = []; if( !empty( $this->mInfo['preview_content'] ) ) { $ret = $this->mInfo['preview_content']->mInfo; } @@ -344,51 +350,51 @@ class FisheyeGallery extends FisheyeBase { return $ret; } - function getImageCount() { + public function getImageCount() { $ret = 0; if ($this->mGalleryId) { - $bindVars = array($this->mContentId); + $bindVars = [ $this->mContentId ]; $whereSql = $selectSql = $joinSql = $orderSql = ''; - $rows = $offset = NULL; - $paramHash['no_fatal'] = TRUE; - $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $paramHash ); + $rows = $offset = null; + $paramHash['no_fatal'] = true; + $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, null, $paramHash ); $query = 'SELECT COUNT(*) AS "count" 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` ) $joinSql WHERE `gallery_content_id` = ? $whereSql"; - $rs = $this->mDb->query($query, $bindVars); - $ret = $rs->fields['count']; + $rs = $this->mDb->getRow($query, $bindVars); + $ret = $rs['count']; } return $ret; } - function verifyGalleryData(&$pStorageHash) { + public function verifyGalleryData(&$pParamHash) { global $gBitSystem; - if (empty($pStorageHash['rows_per_page'])) { - $pStorageHash['rows_per_page'] = $gBitSystem->getConfig('fisheye_gallery_default_rows_per_page', (!empty($this->mInfo['rows_per_page']) ? $this->mInfo['rows_per_page'] : FISHEYE_DEFAULT_ROWS_PER_PAGE)); + if (empty($pParamHash['rows_per_page'])) { + $pParamHash['rows_per_page'] = $gBitSystem->getConfig('fisheye_gallery_default_rows_per_page', !empty($this->mInfo['rows_per_page']) ? $this->mInfo['rows_per_page'] : FISHEYE_DEFAULT_ROWS_PER_PAGE); } - if (empty($pStorageHash['cols_per_page'])) { - $pStorageHash['cols_per_page'] = $gBitSystem->getConfig('fisheye_gallery_default_cols_per_page', (!empty($this->mInfo['cols_per_page']) ? $this->mInfo['cols_per_page'] : FISHEYE_DEFAULT_COLS_PER_PAGE)); + if (empty($pParamHash['cols_per_page'])) { + $pParamHash['cols_per_page'] = $gBitSystem->getConfig('fisheye_gallery_default_cols_per_page', !empty($this->mInfo['cols_per_page']) ? $this->mInfo['cols_per_page'] : FISHEYE_DEFAULT_COLS_PER_PAGE); } - if (empty($pStorageHash['thumbnail_size'])) { - $pStorageHash['thumbnail_size'] = $gBitSystem->getConfig('fisheye_gallery_default_thumbnail_size', (!empty($this->mInfo['thumbnail_size']) ? $this->mInfo['thumbnail_size'] : NULL )); + if (empty($pParamHash['thumbnail_size'])) { + $pParamHash['thumbnail_size'] = $gBitSystem->getConfig('fisheye_gallery_default_thumbnail_size', !empty($this->mInfo['thumbnail_size']) ? $this->mInfo['thumbnail_size'] : 'small'); } - if (empty($pStorageHash['title'])) { + if (empty($pParamHash['title'])) { $this->mErrors[] = "You must specify a title for this image gallery"; } - $pStorageHash['content_type_guid'] = $this->getContentType(); + $pParamHash['content_type_guid'] = $this->getContentType(); - return (count($this->mErrors) == 0); + return count($this->mErrors) == 0; } - function generateThumbnails() { + public function generateGalleryThumbnails(): void { if( $this->isValid() ) { if( $this->loadImages() ) { foreach( array_keys( $this->mItems ) as $key ) { @@ -399,14 +405,14 @@ class FisheyeGallery extends FisheyeBase { } - function getThumbnailContentId() { + public function getThumbnailContentId() { if( !$this->getField( 'thumbnail_content_id' ) ) { $this->getThumbnailImage(); } - return( $this->getField( 'thumbnail_content_id' ) ); + return $this->getField( 'thumbnail_content_id' ); } - function getThumbnailUri( $pSize='small', $pInfoHash = NULL ) { + public function getThumbnailUri( $pSize='small', $pInfoHash = null ) { if( empty( $this->mInfo['preview_content'] ) ) { $this->loadThumbnail(); } @@ -417,7 +423,7 @@ class FisheyeGallery extends FisheyeBase { } - function getThumbnailUrl( $pSize = 'small', $pInfoHash = NULL, $pSecondaryId = NULL, $pDefault=TRUE ) { + public function getThumbnailUrl( string $pSize = 'small', ?array $pInfoHash = null, ?int $pSecondaryId = null, ?int $pDefault = null ): string|null { if( empty( $this->mInfo['preview_content'] ) ) { $this->loadThumbnail(); } @@ -425,26 +431,27 @@ class FisheyeGallery extends FisheyeBase { if( is_object( $this->mInfo['preview_content'] ) ) { return $this->mInfo['preview_content']->getThumbnailUrl( $pSize ); } + return ''; } - function getThumbnailImage( $pContentId=NULL, $pThumbnailContentId=NULL, $pThumbnailContentType=NULL ) { + public function getThumbnailImage( $pContentId=null, $pThumbnailContentId=null, $pThumbnailContentType=null ) { global $gLibertySystem, $gBitUser; - $ret = NULL; + $ret = null; if( !@$this->verifyId( $pContentId ) && !empty( $this->mContentId ) ) { $pContentId = $this->mContentId; } if( !@$this->verifyId( $pThumbnailContentId ) ) { - if( @$this->verifyId( $this->mInfo['preview_content_id'] ) ) { + if( @$this->verifyId( $this->mInfo['preview_content_id'] ?? 0 ) ) { $pThumbnailContentId = $this->mInfo['preview_content_id']; } else { if( $this->mDb->isAdvancedPostgresEnabled() ) { $whereSql = ''; - $bindVars = array( $pContentId ); + $bindVars = [ $pContentId ]; if( !$gBitUser->isAdmin() ) { - $whereSql = " AND (cgm.`security_id` IS NULL OR lc.`user_id`=?) "; + $whereSql = " AND (cgm.`security_id` IS null OR lc.`user_id`=?) "; $bindVars[] = $gBitUser->mUserId; } $query = "SELECT COALESCE( fg.`preview_content_id`, lc.`content_id` ) AS `content_id`, lc.`content_type_guid` @@ -461,10 +468,10 @@ class FisheyeGallery extends FisheyeBase { FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( fgim.`item_content_id`=lc.`content_id` ) WHERE fgim.`gallery_content_id` = ? ORDER BY ".$this->mDb->convertSortmode('random'); - $rs = $this->mDb->query($query, array( $pContentId ), 1); - if( !empty( $rs->fields ) ) { - $pThumbnailContentId = $rs->fields['item_content_id']; - $pThumbnailContentType = $rs->fields['content_type_guid']; + $rs = $this->mDb->getRow($query, [ $pContentId ], 1); + if( !empty( $rs ) ) { + $pThumbnailContentId = $rs['item_content_id']; + $pThumbnailContentType = $rs['content_type_guid']; } } } @@ -485,7 +492,7 @@ class FisheyeGallery extends FisheyeBase { } - function loadThumbnail( $pSize='small', $pContentId=NULL ) { + public function loadThumbnail( $pSize='small', $pContentId=null ) { if( $this->mPreviewImage = $this->getThumbnailImage( $pContentId ) ) { $this->mInfo['preview_content'] = &$this->mPreviewImage; $this->mInfo['image_file'] = &$this->mPreviewImage->mInfo['image_file']; @@ -493,40 +500,40 @@ class FisheyeGallery extends FisheyeBase { } - function storeGalleryThumbnail($pContentId = NULL) { - $ret = FALSE; + public function storeGalleryThumbnail($pContentId = null) { + $ret = false; if ($pContentId && !$this->isInGallery( $this->mContentId, $pContentId ) ) { - return FALSE; + return false; } if ($this->mGalleryId) { if (!$pContentId) - $pContentId = NULL; + $pContentId = null; $query = "UPDATE `".BIT_DB_PREFIX."fisheye_gallery` SET `preview_content_id` = ? WHERE `gallery_id`= ?"; - $rs = $this->mDb->query($query, array($pContentId, $this->mGalleryId)); + $rs = $this->mDb->getOne($query, [ $pContentId, $this->mGalleryId ] ); $this->mInfo['preview_content_id'] = $pContentId; - $ret = TRUE; + $ret = true; } return $ret; } - function store(&$pStorageHash) { - if ($this->verifyGalleryData($pStorageHash)) { + public function store( array &$pParamHash ): bool { + if ($this->verifyGalleryData($pParamHash)) { $this->StartTrans(); - if( LibertyContent::store($pStorageHash)) { - $this->mContentId = $pStorageHash['content_id']; + if( LibertyContent::store($pParamHash)) { + $this->mContentId = $pParamHash['content_id']; $this->mInfo['content_id'] = $this->mContentId; if ($this->galleryExistsInDatabase()) { $query = "UPDATE `".BIT_DB_PREFIX."fisheye_gallery` SET `rows_per_page` = ?, `cols_per_page` = ?, `thumbnail_size` = ? WHERE `gallery_id` = ?"; - $bindVars = array($pStorageHash['rows_per_page'], $pStorageHash['cols_per_page'], $pStorageHash['thumbnail_size'], $this->mGalleryId); + $bindVars = [ $pParamHash['rows_per_page'], $pParamHash['cols_per_page'], $pParamHash['thumbnail_size'], $this->mGalleryId ]; } else { $this->mGalleryId = $this->mDb->GenID('fisheye_gallery_id_seq'); $this->mInfo['gallery_id'] = $this->mGalleryId; $query = "INSERT INTO `".BIT_DB_PREFIX."fisheye_gallery` (`gallery_id`, `content_id`, `rows_per_page`, `cols_per_page`, `thumbnail_size`) VALUES (?,?,?,?,?)"; - $bindVars = array($this->mGalleryId, $this->mContentId, $pStorageHash['rows_per_page'], $pStorageHash['cols_per_page'], $pStorageHash['thumbnail_size']); + $bindVars = [ $this->mGalleryId, $this->mContentId, $pParamHash['rows_per_page'], $pParamHash['cols_per_page'], $pParamHash['thumbnail_size'] ]; } - $rs = $this->mDb->query($query, $bindVars); + $rs = $this->mDb->getOne($query, $bindVars); $this->CompleteTrans(); } else { $this->mDb->RollbackTrans(); @@ -536,16 +543,16 @@ class FisheyeGallery extends FisheyeBase { $this->mErrors[] = "There were errors while attempting to save this gallery"; } - return (count($this->mErrors) == 0); + return count($this->mErrors) == 0; } - function removeItem( $pContentId ) { - $ret = FALSE; + public function removeItem( $pContentId ) { + $ret = false; if( $this->isValid() && @$this->verifyId( $pContentId ) ) { $query = "DELETE FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE `item_content_id`=? AND `gallery_content_id`=?"; - $rs = $this->mDb->query($query, array($pContentId, $this->mContentId ) ); - $ret = TRUE; + $rs = $this->mDb->getOne($query, [ $pContentId, $this->mContentId ] ); + $ret = true; } return $ret; } @@ -553,36 +560,38 @@ class FisheyeGallery extends FisheyeBase { /** * Adds a new item (image or gallery) to this gallery. We check to make sure we are not a member * of this gallery and this gallery is not a member of the new item to avoid infinite recursion scenarios - * @return boolean wheter or not the item was added + * @return bool wheter or not the item was added */ - function addItem( $pContentId, $pPosition=NULL ) { + public function addItem( $pContentId, $pPosition=null ) { global $gBitSystem; - $ret = FALSE; + $ret = false; if( @$this->verifyId( $this->mContentId ) && @$this->verifyId( $pContentId ) && ( $this->mContentId != $pContentId ) && !$this->isInGallery( $this->mContentId, $pContentId ) && !$this->isInGallery( $pContentId, $this->mContentId ) ) { $query = "INSERT INTO `".BIT_DB_PREFIX."fisheye_gallery_image_map` (`item_content_id`, `gallery_content_id`, `item_position`) VALUES (?,?,?)"; - $rs = $this->mDb->query($query, array($pContentId, $this->mContentId, $pPosition ) ); + $rs = $this->mDb->getOne($query, [ $pContentId, $this->mContentId, $pPosition ] ); $query = "UPDATE `".BIT_DB_PREFIX."liberty_content` SET `last_modified`=? WHERE `content_id`=?"; - $rs = $this->mDb->query( $query, array( $gBitSystem->getUTCTime(), $this->mContentId ) ); - $ret = TRUE; + $rs = $this->mDb->getOne( $query, [ $gBitSystem->getUTCTime(), $this->mContentId ] ); + $ret = true; } return $ret; } - function expunge( $pRecursiveDelete = FALSE ) { + public function expunge(): bool { if( $this->isValid() ) { $this->StartTrans(); if( $this->loadImages() ) { foreach( array_keys( $this->mItems ) as $key ) { - if( $pRecursiveDelete ) { - $this->mItems[$key]->expunge( $pRecursiveDelete ); - } elseif( is_a( $this->mItems[$key], 'FisheyeImage' ) ) { +// TODO Recersive delete needs another implementation +// if( !empty($pRecursiveDelete) ) { +// $this->mItems[$key]->expunge( $pRecursiveDelete ); +// } else + if( is_a( $this->mItems[$key], 'FisheyeImage' ) ) { // make sure we have a valid content_id before we exec if( is_numeric( $this->mItems[$key]->mContentId ) ) { $query = "SELECT COUNT(`item_content_id`) AS `other_gallery` FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE `item_content_id`=? AND `gallery_content_id`!=?"; - if( !($inOtherGallery = $this->mDb->getOne($query, array($this->mItems[$key]->mContentId, $this->mContentId ) )) ) { + if( !($inOtherGallery = $this->mDb->getOne($query, [ $this->mItems[$key]->mContentId, $this->mContentId ] )) ) { $this->mItems[$key]->expunge(); } } @@ -591,32 +600,32 @@ class FisheyeGallery extends FisheyeBase { } $query = "DELETE FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE `gallery_content_id`=?"; - $rs = $this->mDb->query($query, array( $this->mContentId ) ); + $rs = $this->mDb->getOne($query, [ $this->mContentId ] ); $query = "DELETE FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE `item_content_id`=?"; - $rs = $this->mDb->query($query, array( $this->mContentId ) ); + $rs = $this->mDb->getOne($query, [ $this->mContentId ] ); $query = "DELETE FROM `".BIT_DB_PREFIX."fisheye_gallery` WHERE `content_id`=?"; - $rs = $this->mDb->query($query, array( $this->mContentId ) ); + $rs = $this->mDb->getOne($query, [ $this->mContentId ] ); if( LibertyContent::expunge() ) { $this->CompleteTrans(); } else { $this->mDb->RollbackTrans(); - error_log( "Error expunging fisheye gallery: " . vc($this->mErrors ) ); + error_log( "Error expunging fisheye gallery: " . \Bitweaver\vc($this->mErrors ) ); } } - return( count( $this->mErrors ) == 0 ); + return true; } - function galleryExistsInDatabase() { - $ret = FALSE; + public function galleryExistsInDatabase() { + $ret = false; if( @$this->verifyId( $this->mGalleryId ) ) { $query = "SELECT COUNT(`gallery_id`) AS `gcount` FROM `".BIT_DB_PREFIX."fisheye_gallery` WHERE `gallery_id` = ?"; - $rs = $this->mDb->query($query, array($this->mGalleryId)); - if ($rs->fields['gcount'] > 0) - $ret = TRUE; + $rs = $this->mDb->getOne($query, [ $this->mGalleryId ] ); + if ($rs > 0) + $ret = true; } return $ret; @@ -624,48 +633,48 @@ class FisheyeGallery extends FisheyeBase { /** * Returns the layout of the gallery accounting for various defaults - * @return the layout string preference + * @return string the layout string preference */ - function getLayout() { + public function getLayout() { global $gBitSystem; return $this->getPreference( 'gallery_pagination', $gBitSystem->getConfig( 'default_gallery_pagination', FISHEYE_PAGINATION_GALLERIFFIC ) ); } public static function getAllLayouts() { - return array( + return [ FISHEYE_PAGINATION_GALLERIFFIC => 'Galleriffic', FISHEYE_PAGINATION_FIXED_GRID => 'Fixed Grid', FISHEYE_PAGINATION_AUTO_FLOW => 'Auto-Flow Images', FISHEYE_PAGINATION_POSITION_NUMBER => 'Image Order Page Number', FISHEYE_PAGINATION_SIMPLE_LIST => 'Simple List', // FISHEYE_PAGINATION_MATTEO => 'Matteo', - ); + ]; } /** * Returns include file that will setup the object for rendering - * @return the fully specified path to file to be included + * @return string the fully specified path to file to be included */ - function getRenderFile() { + public function getRenderFile() { return FISHEYE_PKG_INCLUDE_PATH.'display_fisheye_gallery_inc.php'; } /** * Returns template file used for display - * @return the fully specified path to file to be included + * @return string the fully specified path to file to be included */ - function getRenderTemplate() { + public function getRenderTemplate() { return 'bitpackage:fisheye/view_gallery.tpl'; } /** * Function that returns link to display a piece of content - * @param pGalleryId id of gallery to link - * @return the url to display the gallery. + * @param array pGalleryId id of gallery to link + * @return string the url to display the gallery. */ public static function getDisplayUrlFromHash( &$pParamHash ) { - $path = NULL; - + $path = null; + $ret = ''; if( BitBase::verifyIdParameter( $pParamHash, 'gallery_id' ) ) { $ret = FISHEYE_PKG_URL; global $gBitSystem; @@ -677,19 +686,19 @@ class FisheyeGallery extends FisheyeBase { $ret .= '&gallery_path='.$pParamHash['path']; } } - } elseif( @BitBase::verifyId( $pParamHash['content_id'] ) ) { + } elseif( BitBase::verifyId( $pParamHash['content_id'] ?? 0 ) ) { $ret = FISHEYE_PKG_URL.'view.php?content_id='.$pParamHash['content_id']; } return $ret; } - function getTree( $pListHash ) { + public function getTree( $pListHash ) { global $gBitDb; - $ret = array(); + $ret = []; if( $this->mDb->isAdvancedPostgresEnabled() ) { - $bindVars = array(); - $containVars = array(); + $bindVars = []; + $containVars = []; $selectSql = ''; $joinSql = ''; $whereSql = ''; @@ -717,7 +726,7 @@ class FisheyeGallery extends FisheyeBase { $rootContent = $gBitDb->GetAssoc( $query, $bindVars ); foreach( array_keys( $rootContent ) as $conId ) { - $splitVars = array(); + $splitVars = []; $query = "SELECT branch AS hash_key, * $selectSql FROM connectby('`".BIT_DB_PREFIX."fisheye_gallery_image_map`', '`item_content_id`', '`gallery_content_id`', ?, 0, '/') AS t(cb_item_content_id int,cb_gallery_content_id int, level int, branch text) INNER JOIN `".BIT_DB_PREFIX."fisheye_gallery` fg ON (fg.`content_id`=cb_item_content_id) @@ -732,9 +741,9 @@ class FisheyeGallery extends FisheyeBase { FisheyeGallery::splitConnectByTree( $ret, $gBitDb->GetAssoc( $query, $splitVars ) ); FisheyeGallery::getTreeSort( $ret ); } - } else if ( $this->mDb->mType == 'firebird' ) { - $bindVars = array(); - $containVars = array(); + } else if ( $this->mDb->mType == 'firebird' || $this->mDb->mType == 'pdo' ) { + $bindVars = []; + $containVars = []; $selectSql = ''; $joinSql = ''; $whereSql = ''; @@ -756,7 +765,7 @@ class FisheyeGallery extends FisheyeBase { $bindVars[] = $val; } - $splitVars = array(); + $splitVars = []; $query = "WITH RECURSIVE GALLERY_TREE AS ( SELECT B.`content_id` AS gallery_content_id, B.`content_id` AS item_content_id, 0 AS BLEVEL, CAST( lcp.`title` AS VARCHAR(255) ) AS BRANCH, 0 AS gallery_parent_id @@ -766,11 +775,11 @@ class FisheyeGallery extends FisheyeBase { UNION ALL - SELECT `item_content_id` AS gallery_content_id, `item_content_id`, G.BLEVEL + 1, G.BRANCH || '/' || `item_content_id` AS BRANCH, `gallery_content_id` AS gallery_parent_id + SELECT G1.`item_content_id` AS gallery_content_id, G1.`item_content_id`, G.BLEVEL + 1, G.BRANCH || '/' || G1.`item_content_id` AS BRANCH, G1.`gallery_content_id` AS gallery_parent_id FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` G1 JOIN GALLERY_TREE G ON G1.`gallery_content_id` = G.`item_content_id` - INNER JOIN `".BIT_DB_PREFIX."liberty_content` lcg1 ON(lcg1.`content_id`=`item_content_id`) and lcg1.`content_type_guid` = 'fisheyegallery' + INNER JOIN `".BIT_DB_PREFIX."liberty_content` lcg1 ON(lcg1.`content_id`=G1.`item_content_id`) and lcg1.`content_type_guid` = 'fisheyegallery' ) SELECT T.BRANCH AS hash_key, T.BLEVEL, fg.*, lc.* $selectSql FROM GALLERY_TREE T @@ -791,7 +800,7 @@ class FisheyeGallery extends FisheyeBase { } else { // this needs replacing with a more suitable list query ... - $pListHash['show_empty'] = TRUE; + $pListHash['show_empty'] = true; $galList = $this->getList( $pListHash ); // index by content_id foreach( $galList as $galId => $gal ) { @@ -800,25 +809,25 @@ class FisheyeGallery extends FisheyeBase { FisheyeGallery::splitConnectByTree( $ret, $ret ); FisheyeGallery::getTreeSort( $ret ); } - return( $ret ); + return $ret; } - function getTreeSort( &$pTree ) { + public function getTreeSort( &$pTree ) { if( $pTree ) { foreach( array_keys( $pTree ) as $k ) { if( !empty( $pTree[$k]['children'] ) ) { FisheyeGallery::getTreeSort( $pTree[$k]['children'] ); } } - uasort( $pTree, array( 'FisheyeGallery', 'getTreeSortCmp' ) ); + uasort( $pTree, [ 'FisheyeGallery', 'getTreeSortCmp' ] ); } } - static function getTreeSortCmp( $a, $b ) { + public static function getTreeSortCmp( $a, $b ) { return strcmp( $a['content']['title'], $b['content']['title'] ); } - function splitConnectByTree( &$pRet, $pTreeHash ) { + public function splitConnectByTree( &$pRet, $pTreeHash ) { if( $pTreeHash ) { foreach( array_keys( $pTreeHash ) as $conId ) { $path = explode( '/', $conId ); @@ -827,11 +836,11 @@ class FisheyeGallery extends FisheyeBase { } } - function recurseConnectByPath( &$pRet, $pTreeHash, $pPath ) { + public function recurseConnectByPath( &$pRet, $pTreeHash, $pPath ) { $popId = array_shift( $pPath ); if( count( $pPath ) > 0 ) { if( empty( $pRet[$popId]['children'] ) ) { - $pRet[$popId]['children'] = array(); + $pRet[$popId]['children'] = []; } FisheyeGallery::recurseConnectByPath( $pRet[$popId]['children'], $pTreeHash, $pPath ); } else { @@ -841,13 +850,13 @@ class FisheyeGallery extends FisheyeBase { } // Generate a nested ul list of listed galleries - function generateList( $pListHash, $pOptions, $pLocate = FALSE ) { + public function generateList( $pListHash, $pOptions, $pLocate = false ) { $ret = ''; if( $hash = FisheyeGallery::getTree( $pListHash ) ) { $class = ' structure-toc'; $ret = "<ul "; - foreach( array( 'class', 'name', 'id', 'onchange' ) as $key ) { + foreach( [ 'class', 'name', 'id', 'onchange' ] as $key ) { if( !empty( $pOptions[$key] ) ) { if( $key == 'class' ) { $class .= ' '.$pOptions[$key]; @@ -864,7 +873,7 @@ class FisheyeGallery extends FisheyeBase { } // Helper method for generateMenu. See that method. Is Recursive - function generateListItems( &$pHash, $pOptions, $pLocate ) { + public function generateListItems( &$pHash, $pOptions, $pLocate ) { $ret = ''; foreach( array_keys( $pHash ) as $conId ) { $class = !empty( $pOptions['radio_checkbox'] ) ? 'checkbox' : ''; @@ -904,9 +913,9 @@ class FisheyeGallery extends FisheyeBase { // Generate a select drop menu of listed galleries - function generateMenu( $pListHash, $pOptions, $pLocate=NULL ) { + public function generateMenu( $pListHash, $pOptions, $pLocate=null ) { $ret = "<select class='form-control' "; - foreach( array( 'class', 'name', 'id', 'onchange' ) as $key ) { + foreach( [ 'class', 'name', 'id', 'onchange' ] as $key ) { if( !empty( $pOptions[$key] ) ) { $ret .= " $key=\"$pOptions[$key]\" "; } @@ -921,7 +930,7 @@ class FisheyeGallery extends FisheyeBase { } // Helper method for generateMenu. See that method. Is Recursive - function generateMenuOptions( &$pHash, $pOptions, $pLocate, $pPrefix='' ) { + public function generateMenuOptions( &$pHash, $pOptions, $pLocate, $pPrefix='' ) { $ret = ''; foreach( array_keys( $pHash ) as $conId ) { $ret .= '<option gallery_id="'.$pHash[$conId]['content']['gallery_id'].'" value="'.$pHash[$conId]['content']['gallery_id'].'"'; @@ -936,26 +945,26 @@ class FisheyeGallery extends FisheyeBase { $ret .= ' >'.($pPrefix?$pPrefix.'» ':'').htmlspecialchars( $pHash[$conId]['content']['title'] ).'</option>'; if( !empty( $pHash[$conId]['children'] ) ) { - $ret .= FisheyeGallery::generateMenuOptions( $pHash[$conId]['children'], $pOptions, $pLocate, ($pPrefix.'-') ); + $ret .= FisheyeGallery::generateMenuOptions( $pHash[$conId]['children'], $pOptions, $pLocate, $pPrefix.'-' ); } } return $ret; } - function getList( &$pListHash ) { + public function getList( &$pListHash ) { global $gBitUser,$gBitSystem, $gBitDbType; - $pListHash['valid_sort_modes'] = array( 'real_name', 'login', 'hits', 'title', 'created', 'last_modified', 'last_hit', 'event_time', 'ip' ); + $pListHash['valid_sort_modes'] = [ 'real_name', 'login', 'hits', 'title', 'created', 'last_modified', 'last_hit', 'event_time', 'ip' ]; LibertyContent::prepGetList( $pListHash ); - $bindVars = array(); + $bindVars = []; $selectSql = $joinSql = $whereSql = $sortSql = ''; if( $gBitDbType == 'mysql' ) { // loser mysql without subselects if( !empty( $pListHash['root_only'] ) ) { $joinSql .= " LEFT OUTER JOIN `".BIT_DB_PREFIX."fisheye_gallery_image_map` tfgim2 ON (tfgim2.`item_content_id`=lc.`content_id`)"; - $whereSql .= ' AND tfgim2.`item_content_id` IS NULL '; + $whereSql .= ' AND tfgim2.`item_content_id` IS null '; } } @@ -965,7 +974,7 @@ class FisheyeGallery extends FisheyeBase { $bindVars[] = $pListHash['contain_item']; } - if( @$this->verifyId( $pListHash['user_id'] ) ) { + if( @$this->verifyId( $pListHash['user_id'] ?? 0 ) ) { $whereSql .= " AND lc.`user_id` = ? "; $bindVars[] = (int)$pListHash['user_id']; } @@ -1023,12 +1032,11 @@ class FisheyeGallery extends FisheyeBase { $mapJoin $joinSql LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` plc ON (fg.`preview_content_id` = plc.`content_id`) $whereSql $sortSql"; - if( $rs = $this->mDb->query( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] ) ) { - $data = $rs->GetAssoc(); + if( $data = $this->mDb->GetAssoc( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] ) ) { if( empty( $pListHash['no_thumbnails'] ) ) { $thumbsize = !empty( $pListHash['thumbnail_size'] ) ? $pListHash['thumbnail_size'] : 'small'; foreach( array_keys( $data ) as $galleryId ) { - $data[$galleryId]['display_url'] = static::getDisplayUrlFromHash( $data[$galleryId] ); + $data[$galleryId]['display_url'] = static::getDisplayUrlFromHash( $data[$galleryId] ); $data[$galleryId]['display_uri'] = static::getDisplayUriFromHash( $data[$galleryId] ); if( $thumbImage = $this->getThumbnailImage( $data[$galleryId]['content_id'], $data[$galleryId]['preview_content_id'], $data[$galleryId]['preview_content_type_guid'] ) ) { $data[$galleryId]['thumbnail_url'] = $thumbImage->getThumbnailUrl( $thumbsize ); @@ -1058,17 +1066,17 @@ class FisheyeGallery extends FisheyeBase { return $data; } - function download(){ + public function download(){ if($this->isValid()){ - $zip = new ZipArchive(); + $zip = new \ZipArchive(); $filename = tempnam(TEMP_PKG_PATH,"galleryzip"); $path = '/'; - if( $zip->open ($filename, ZIPARCHIVE::OVERWRITE) !== TRUE ){ + if( $zip->open ($filename, \ZIPARCHIVE::OVERWRITE) !== true ){ $this->mErrors['download'] = "Unable to create zip file"; }else{ - addGalleryRecursive( $this->mGalleryId , $path, $zip); + addGalleryRecursive( $this->mGalleryId, $zip, $path); } $zip->close(); @@ -1100,9 +1108,9 @@ class FisheyeGallery extends FisheyeBase { } } -function addGalleryRecursive( $pGalleryId , $pPath = '/', &$pZip ){ +function addGalleryRecursive( $pGalleryId, &$pZip, $pPath = '/' ){ - if( $gallery = FisheyeGallery::lookup( array( 'gallery_id' => $pGalleryId ) ) ) { + if( $gallery = FisheyeGallery::lookup( [ 'gallery_id' => $pGalleryId ] ) ) { $gallery->load(); $gallery->loadImages(); $pPath .= $gallery->getTitle().'/'; @@ -1112,10 +1120,8 @@ function addGalleryRecursive( $pGalleryId , $pPath = '/', &$pZip ){ $title = $item->getTitle(); $pZip->addFile($sourcePath, $pPath.$title.substr($sourcePath,strrpos($sourcePath,'.')) ); } elseif ( is_a( $item , 'FisheyeGallery' ) ) { - addGalleryRecursive($item->mGalleryId,$pPath,$pZip); + addGalleryRecursive( $item->mGalleryId, $pZip ,$pPath ); } } } } - -?> diff --git a/includes/classes/FisheyeImage.php b/includes/classes/FisheyeImage.php index 911d8d5..ff33643 100644..100755 --- a/includes/classes/FisheyeImage.php +++ b/includes/classes/FisheyeImage.php @@ -6,9 +6,13 @@ /** * required setup */ -require_once( FISHEYE_PKG_CLASS_PATH.'FisheyeBase.php' ); +namespace Bitweaver\Fisheye; +use Bitweaver\Liberty\LibertyContent; +use Bitweaver\Liberty\LibertyMime; +use Bitweaver\BitBase; + // Needed for getting event_time and possible image title and data -require_once( LIBERTY_PKG_PATH.'plugins/mime.image.php' ); +require_once LIBERTY_PKG_PATH.'plugins/mime.image.php'; define('FISHEYEIMAGE_CONTENT_TYPE_GUID', 'fisheyeimage'); @@ -17,20 +21,22 @@ define('FISHEYEIMAGE_CONTENT_TYPE_GUID', 'fisheyeimage'); */ class FisheyeImage extends FisheyeBase { public $mImageId; + public $mExif; - function __construct($pImageId = NULL, $pContentId = NULL) { + public function __construct($pImageId = null, $pContentId = null) { parent::__construct(); $this->mImageId = (int)$pImageId; $this->mContentId = (int)$pContentId; $this->registerContentType( - FISHEYEIMAGE_CONTENT_TYPE_GUID, array( 'content_type_guid' => FISHEYEIMAGE_CONTENT_TYPE_GUID, + FISHEYEIMAGE_CONTENT_TYPE_GUID, [ + 'content_type_guid' => FISHEYEIMAGE_CONTENT_TYPE_GUID, 'content_name' => 'Image', 'handler_class' => 'FisheyeImage', 'handler_package' => 'fisheye', 'handler_file' => 'FisheyeImage.php', 'maintainer_url' => 'http://www.bitweaver.org' - )); + ] ); // Permission setup $this->mViewContentPerm = 'p_fisheye_view'; @@ -39,23 +45,23 @@ class FisheyeImage extends FisheyeBase { } public function __sleep() { - $ret = array_merge( parent::__sleep(), array( 'mImageId' ) ); + $ret = array_merge( parent::__sleep(), [ 'mImageId' ] ); return $ret; } public static function lookup( $pLookupHash ) { global $gBitDb; - $ret = NULL; + $ret = null; - $lookupContentId = NULL; + $lookupContentId = null; if (!empty($pLookupHash['image_id']) && is_numeric($pLookupHash['image_id'])) { - if( $lookup = $gBitDb->getRow( "SELECT lc.`content_id`, lc.`content_type_guid` FROM `".BIT_DB_PREFIX."fisheye_image` fi INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON(lc.`content_id`=fi.`content_id`) WHERE `image_id`=?", array( $pLookupHash['image_id'] ) ) ) { + if( $lookup = $gBitDb->getRow( "SELECT lc.`content_id`, lc.`content_type_guid` FROM `".BIT_DB_PREFIX."fisheye_image` fi INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON(lc.`content_id`=fi.`content_id`) WHERE `image_id`=?", [ $pLookupHash['image_id'] ] ) ) { $lookupContentId = $lookup['content_id']; $lookupContentGuid = $lookup['content_type_guid']; } } elseif (!empty($pLookupHash['content_id']) && is_numeric($pLookupHash['content_id'])) { $lookupContentId = $pLookupHash['content_id']; - $lookupContentGuid = NULL; + $lookupContentGuid = null; } if( static::verifyId( $lookupContentId ) ) { @@ -68,9 +74,9 @@ class FisheyeImage extends FisheyeBase { public function load() { if( $this->isValid() ) { global $gBitSystem; - $gateSql = NULL; + $gateSql = null; $selectSql = $joinSql = $whereSql = ''; - $bindVars = array(); + $bindVars = []; if ( @$this->verifyId( $this->mImageId ) ) { $whereSql = " WHERE fi.`image_id` = ?"; @@ -97,8 +103,8 @@ class FisheyeImage extends FisheyeBase { $this->mImageId = $this->mInfo['image_id']; $this->mContentId = $this->mInfo['content_id']; - $this->mInfo['creator'] = (isset( $this->mInfo['creator_real_name'] ) ? $this->mInfo['creator_real_name'] : $this->mInfo['creator_user'] ); - $this->mInfo['editor'] = (isset( $this->mInfo['modifier_real_name'] ) ? $this->mInfo['modifier_real_name'] : $this->mInfo['modifier_user'] ); + $this->mInfo['creator'] = isset( $this->mInfo['creator_real_name'] ) ? $this->mInfo['creator_real_name'] : $this->mInfo['creator_user']; + $this->mInfo['editor'] = isset( $this->mInfo['modifier_real_name'] ) ? $this->mInfo['modifier_real_name'] : $this->mInfo['modifier_user']; if( $gBitSystem->isPackageActive( 'gatekeeper' ) && !@$this->verifyId( $this->mInfo['security_id'] ) ) { // check to see if this image is in a protected gallery @@ -107,10 +113,10 @@ class FisheyeImage extends FisheyeBase { INNER JOIN `".BIT_DB_PREFIX."gatekeeper_security_map` tsm ON(fgim.`gallery_content_id`=tsm.`content_id` ) INNER JOIN `".BIT_DB_PREFIX."gatekeeper_security` ls ON(tsm.`security_id`=ls.`security_id` ) WHERE fgim.`item_content_id`=?"; - $grs = $this->mDb->query($query, array( $this->mContentId ) ); - if( $grs && $grs->RecordCount() ) { + $grs = $this->mDb->getAssoc($query, [ $this->mContentId ] ); + if( $grs ) { // order matters here - $this->mInfo = array_merge( $grs->fields, $this->mInfo ); + $this->mInfo = array_merge( $grs, $this->mInfo ); } } @@ -127,7 +133,7 @@ class FisheyeImage extends FisheyeBase { // override original display_url that mime knows where we keep the image $this->mInfo['image_file']['display_url'] = $this->getDisplayUrl(); } else { - $this->mInfo['image_file'] = NULL; + $this->mInfo['image_file'] = null; } if( empty( $this->mInfo['width'] ) || empty( $this->mInfo['height'] ) ) { @@ -136,52 +142,53 @@ class FisheyeImage extends FisheyeBase { if( !empty($details) AND $details['width'] > 0 AND $details['width'] < 9999 AND $details['height'] > 0 AND $details['height'] < 9999 ) { $this->mInfo['width'] = $details['width']; $this->mInfo['height'] = $details['height']; - $this->mDb->query( "UPDATE `".BIT_DB_PREFIX."fisheye_image` SET `width`=?, `height`=? WHERE `content_id`=?", array( $this->mInfo['width'], $this->mInfo['height'], $this->mContentId ) ); + $this->mDb->getOne( "UPDATE `".BIT_DB_PREFIX."fisheye_image` SET `width`=?, `height`=? WHERE `content_id`=?", [ $this->mInfo['width'], $this->mInfo['height'], $this->mContentId ] ); } } } $ret = count($this->mInfo); } else { // We don't have an image_id or a content_id so there is no way to know what to load - $ret = NULL; + $ret = null; } return $ret; } - function storeDimensions( $pDetails ) { + public function storeDimensions( $pDetails ) { if( $this->isValid() && $this->mInfo['width'] != $pDetails['width'] || $this->mInfo['height'] != $pDetails['height'] ) { // if our data got out of sync with the database, force an update $query = "UPDATE `".BIT_DB_PREFIX."fisheye_image` SET `width`=?, `height`=? WHERE `content_id`=?"; - $this->mDb->query( $query, array( $pDetails['width'], $pDetails['height'], $this->mContentId ) ); + $this->mDb->getOne( $query, [ $pDetails['width'], $pDetails['height'], $this->mContentId ] ); $this->mInfo['width'] = $pDetails['width']; $this->mInfo['height'] = $pDetails['height']; $this->clearFromCache(); } } - function exportHash() { - $ret = NULL; + public function exportHash() { + $ret = null; // make sure we have a valid image file. if( ($ret = parent::exportHash()) && ($details = $this->getImageDetails() ) ) { - $ret = array_merge( $ret, array( 'type' => $this->getContentType(), + $ret = array_merge( $ret, [ + 'type' => $this->getContentType(), 'landscape' => $this->isLandscape(), 'has_description' => !empty( $this->mInfo['data'] ), 'is_favorite' => $this->getField('is_favorite'), - ) ); + ] ); } return $ret; } - function isLandscape() { - return( !empty( $this->mInfo['width'] ) && !empty( $this->mInfo['height'] ) && ($this->mInfo['width'] > $this->mInfo['height']) ); + public function isLandscape() { + return !empty( $this->mInfo['width'] ) && !empty( $this->mInfo['height'] ) && ($this->mInfo['width'] > $this->mInfo['height']); } - function verifyImageData(&$pParamHash) { + public function verifyImageData(&$pParamHash) { $pParamHash['content_type_guid'] = $this->getContentType(); if ( empty($pParamHash['purge_from_galleries']) ) { - $pParamHash['purge_from_galleries'] = FALSE; + $pParamHash['purge_from_galleries'] = false; } if( !empty( $pParamHash['resize'] ) ) { @@ -197,10 +204,10 @@ class FisheyeImage extends FisheyeBase { } } - if( function_exists( 'mime_image_get_exif_data' ) && !empty( $pParamHash['_files_override'][0]['tmp_name'] ) ) { + if( function_exists( '\Bitweaver\Liberty\mime_image_get_exif_data' ) && !empty( $pParamHash['_files_override'][0]['tmp_name'] ) ) { $exifFile['source_file'] = $pParamHash['_files_override'][0]['tmp_name']; $exifFile['type'] = $pParamHash['_files_override'][0]['type']; - $exifHash = mime_image_get_exif_data( $exifFile ); + $exifHash = \Bitweaver\Liberty\mime_image_get_exif_data( $exifFile ); // Set some default values based on the Exif data if( !empty( $exifHash['IFD0']['ImageDescription'] ) ) { @@ -258,10 +265,10 @@ class FisheyeImage extends FisheyeBase { parent::verify( $pParamHash ); } - return (count($this->mErrors) == 0); + return count($this->mErrors) == 0; } - function store(&$pParamHash) { + public function store( array &$pParamHash): bool { global $gBitSystem, $gLibertySystem; if ($this->verifyImageData($pParamHash)) { @@ -271,11 +278,11 @@ class FisheyeImage extends FisheyeBase { $currentImageAttachmentId = $this->mInfo['attachment_id']; $pParamHash['attachment_id'] = $currentImageAttachmentId; } else { - $currentImageAttachmentId = NULL; + $currentImageAttachmentId = null; } // we have already done all the permission checking needed for this user to upload an image - $pParamHash['no_perm_check'] = TRUE; + $pParamHash['no_perm_check'] = true; $this->StartTrans(); $pParamHash['thumbnail'] = !$gBitSystem->isFeatureActive( 'liberty_offline_thumbnailer' ); @@ -287,34 +294,31 @@ class FisheyeImage extends FisheyeBase { $this->mContentId = $pParamHash['content_id']; $this->mInfo['content_id'] = $this->mContentId; - if ( !empty( $this->mInfo['source_file'] ) && file_exists( $this->getSourceFile() )) { - $imageDetails = $this->getImageDetails( $this->getSourceFile() ); - } else { - $imageDetails = NULL; - } + $imageDetails = !empty( $this->mInfo['source_file'] ) && file_exists( $this->getSourceFile() ) + ? $imageDetails = $this->getImageDetails( $this->getSourceFile() ) : null; if (!$imageDetails) { - $imageDetails['width'] = (!empty($this->mInfo['width']) ? $this->mInfo['width'] : NULL); - $imageDetails['height'] = (!empty($this->mInfo['height']) ? $this->mInfo['height'] : NULL); + $imageDetails['width'] = !empty($this->mInfo['width']) ? $this->mInfo['width'] : null; + $imageDetails['height'] = !empty($this->mInfo['height']) ? $this->mInfo['height'] : null; } if ($this->imageExistsInDatabase()) { $sql = "UPDATE `".BIT_DB_PREFIX."fisheye_image` SET `content_id` = ?, `width` = ?, `height` = ? WHERE `image_id` = ?"; - $bindVars = array($this->mContentId, $imageDetails['width'], $imageDetails['height'], $this->mImageId); + $bindVars = [ $this->mContentId, $imageDetails['width'], $imageDetails['height'], $this->mImageId ]; } else { $this->mImageId = defined( 'LINKED_ATTACHMENTS' ) ? $this->mContentId : $this->mDb->GenID('fisheye_image_id_seq'); $this->mInfo['image_id'] = $this->mImageId; $sql = "INSERT INTO `".BIT_DB_PREFIX."fisheye_image` (`image_id`, `content_id`, `width`, `height`) VALUES (?,?,?,?)"; - $bindVars = array($this->mImageId, $this->mContentId, $imageDetails['width'], $imageDetails['height']); + $bindVars = [ $this->mImageId, $this->mContentId, $imageDetails['width'], $imageDetails['height'] ]; } - $rs = $this->mDb->query($sql, $bindVars); + $rs = $this->mDb->getOne($sql, $bindVars); // check to see if we need offline thumbnailing if( $gBitSystem->isFeatureActive( 'liberty_offline_thumbnailer' ) ) { - $resize = !empty( $pParamHash['resize'] ) ? (int)$pParamHash['resize'] : NULL; + $resize = !empty( $pParamHash['resize'] ) ? (int)$pParamHash['resize'] : null; $this->generateThumbnails( $resize ); } else { if( !empty( $pParamHash['resize'] ) && is_numeric( $pParamHash['resize'] ) ) { @@ -329,12 +333,12 @@ class FisheyeImage extends FisheyeBase { } else { $this->mErrors[] = "There were errors while attempting to save this gallery image"; } - return (count($this->mErrors) == 0); + return count($this->mErrors) == 0; } - function getExifField( $pExifField ) { - $ret = NULL; - if( function_exists( 'exif_read_data' ) ) { + public function getExifField( $pExifField ) { + $ret = null; + if( function_exists( '\exif_read_data' ) ) { $pExifField = strtolower( $pExifField ); $file = $this->getSourceFile(); // only attempt to get exif data from jpg or tiff files - chokes otherwise @@ -350,7 +354,7 @@ class FisheyeImage extends FisheyeBase { return $ret; } - function rotateImage( $pDegrees, $pImmediateRender = FALSE ) { + public function rotateImage( $pDegrees, $pImmediateRender = false ) { global $gBitSystem; if( $this->getField( 'file_name' ) || $this->load() ) { $fileHash['source_file'] = $this->getSourceFile(); @@ -359,7 +363,7 @@ class FisheyeImage extends FisheyeBase { $fileHash['size'] = filesize( $fileHash['source_file'] ); $fileHash['dest_branch'] = dirname( $this->getSourceFile() ).'/'; $fileHash['name'] = $this->getField( 'file_name' ); - if( $pDegrees == 'auto' ) { + if( $pDegrees == 'auto' ) { if( $exifOrientation = $this->getExifField( 'orientation' ) ) { switch( $exifOrientation ) { case 1: //) transform="";; @@ -394,11 +398,11 @@ class FisheyeImage extends FisheyeBase { if( is_numeric( $pDegrees ) ) { $fileHash['degrees'] = $pDegrees; - if( ($rotateFunc = liberty_get_function( 'rotate' )) && $rotateFunc( $fileHash ) ) { - liberty_clear_thumbnails( $fileHash ); - $this->mDb->query( "UPDATE `".BIT_DB_PREFIX."fisheye_image` SET `width`=`height`, `height`=`width` WHERE `content_id`=?", array( $this->mContentId ) ); + if( ($rotateFunc = \Bitweaver\Liberty\liberty_get_function( 'rotate' )) && $rotateFunc( $fileHash ) ) { + \Bitweaver\Liberty\liberty_clear_thumbnails( $fileHash ); + $this->mDb->getOne( "UPDATE `".BIT_DB_PREFIX."fisheye_image` SET `width`=`height`, `height`=`width` WHERE `content_id`=?", [ $this->mContentId ] ); $this->clearFromCache(); - $this->generateThumbnails( FALSE, $pImmediateRender ); + $this->generateThumbnails( false, $pImmediateRender ); } else { $this->mErrors['rotate'] = $fileHash['error']; } @@ -406,7 +410,7 @@ class FisheyeImage extends FisheyeBase { $this->mErrors['rotate'] = "Image was not auto-rotated."; } } - return (count($this->mErrors) == 0); + return count($this->mErrors) == 0; } @@ -415,11 +419,11 @@ class FisheyeImage extends FisheyeBase { * * @param string $pColorSpace - target color space, only 'grayscale' is currently supported, and only when using the MagickWand image processor * @access public - * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + * @return bool true on success, false on failure - mErrors will contain reason for failure */ - function convertColorspace( $pColorSpace ) { + public function convertColorspace( $pColorSpace ) { global $gBitSystem; - $ret = FALSE; + $ret = false; if( $this->getField( 'file_name' ) || $this->load() ) { $fileHash['source_file'] = $this->getSourceFile(); $fileHash['dest_base_name'] = preg_replace('/(.+)\..*$/', '$1', basename( $fileHash['source_file'] ) ); @@ -427,11 +431,11 @@ class FisheyeImage extends FisheyeBase { $fileHash['size'] = filesize( $fileHash['source_file'] ); $fileHash['dest_branch'] = dirname( $this->getSourceFile() ).'/'; $fileHash['name'] = $this->getField( 'file_name' ); - if( $convertFunc = liberty_get_function( 'convert_colorspace' ) ) { + if( $convertFunc = \Bitweaver\Liberty\liberty_get_function( 'convert_colorspace' ) ) { if( $ret = $convertFunc( $fileHash, $pColorSpace ) ) { - liberty_clear_thumbnails( $fileHash ); + \Bitweaver\Liberty\liberty_clear_thumbnails( $fileHash ); $sql = "UPDATE `".BIT_DB_PREFIX."liberty_files SET `file_size`=? WHERE `file_id` = ?"; - $this->mDb->query( $sql, array( filesize( $fileHash['dest_file'] ), $this->mInfo['file_id'] ) ); + $this->mDb->getOne( $sql, [ filesize( $fileHash['dest_file'] ), $this->mInfo['file_id'] ] ); $this->generateThumbnails(); } } @@ -440,7 +444,7 @@ class FisheyeImage extends FisheyeBase { } - function resizeOriginal( $pResizeOriginal ) { + public function resizeOriginal( $pResizeOriginal ) { global $gBitSystem; if( $this->getField( 'file_name' ) || $this->load() ) { $fileHash['source_file'] = $this->getSourceFile(); @@ -452,7 +456,7 @@ class FisheyeImage extends FisheyeBase { $fileHash['max_height'] = $fileHash['max_width'] = $pResizeOriginal; // make a copy of the fileHash that we can compare output after processing $preResize = $fileHash; - if( ($resizeFunc = liberty_get_function( 'resize' )) && ($resizeFile = $resizeFunc( $fileHash )) ) { + if( ($resizeFunc = \Bitweaver\Liberty\liberty_get_function( 'resize' )) && ($resizeFile = $resizeFunc( $fileHash )) ) { clearstatcache(); // Ack this is evil direct bashing of the liberty tables! XOXO spiderr // should be a cleaner way eventually @@ -467,15 +471,15 @@ class FisheyeImage extends FisheyeBase { } $details = $this->getImageDetails( $resizeFile ); // store all the values that might have changed due to the resize - $storeHash = array( + $storeHash = [ 'file_size' => filesize( $resizeFile ), 'mime_type' => $details['mime'], - ); - $this->mDb->associateUpdate( BIT_DB_PREFIX."liberty_files", $storeHash, array( 'file_id' => $this->mInfo['file_id'] ) ); + ]; + $this->mDb->associateUpdate( BIT_DB_PREFIX."liberty_files", $storeHash, [ 'file_id' => $this->mInfo['file_id'] ] ); //$query = "UPDATE `".BIT_DB_PREFIX."liberty_files` SET `file_size`=? WHERE `file_id`=?"; - //$this->mDb->query( $query, array( $details['size'], $this->mInfo['file_id'] ) ); + //$this->mDb->query( $query, [ $details['size'], $this->mInfo['file_id'] ] ); $query = "UPDATE `".BIT_DB_PREFIX."fisheye_image` SET `width`=?, `height`=? WHERE `content_id`=?"; - $this->mDb->query( $query, array( $details['width'], $details['height'], $this->mContentId ) ); + $this->mDb->getOne( $query, [ $details['width'], $details['height'], $this->mContentId ] ); // if we've come this far, we can try removing the original if it's different to the resized image // make absolutely certain that we have 2 image files and that they are different, then remove the original if( $fileHash['source_file'] != $preResize['source_file'] && is_file( $fileHash['source_file'] ) && is_file( $preResize['source_file'] ) ) { @@ -485,21 +489,21 @@ class FisheyeImage extends FisheyeBase { $this->mErrors['resize'] = $fileHash['error']; } } - return (count($this->mErrors) == 0); + return count($this->mErrors) == 0; } - function generateThumbnails( $pResizeOriginal=NULL, $pImmediateRender=FALSE ) { + public function generateThumbnails( $pResizeOriginal=null, $pImmediateRender=false ) { global $gBitSystem; - $ret = FALSE; + $ret = false; // LibertyMime will take care of thumbnail generation of the offline thumbnailer is not active if( $gBitSystem->isFeatureActive( 'liberty_offline_thumbnailer' ) && !$pImmediateRender ) { $query = "DELETE FROM `".BIT_DB_PREFIX."liberty_process_queue` WHERE `content_id`=?"; - $this->mDb->query( $query, array( $this->mContentId ) ); + $this->mDb->getOne( $query, [ $this->mContentId ] ); $query = "INSERT INTO `".BIT_DB_PREFIX."liberty_process_queue` (`content_id`, `queue_date`, `processor_parameters`) VALUES (?,?,?)"; - $this->mDb->query( $query, array( $this->mContentId, $gBitSystem->getUTCTime(), serialize( array( 'resize_original' => $pResizeOriginal ) ) ) ); + $this->mDb->getOne( $query, [ $this->mContentId, $gBitSystem->getUTCTime(), serialize( [ 'resize_original' => $pResizeOriginal ] ) ] ); } else { $ret = $this->renderThumbnails(); } @@ -507,7 +511,7 @@ class FisheyeImage extends FisheyeBase { } - function renderThumbnails( $pThumbSizes=NULL ) { + public function renderThumbnails( $pThumbSizes=null ) { global $gBitSystem; if( $this->getField( 'file_name' ) || $this->load() ) { $fileHash['source_file'] = $this->getSourceFile(); @@ -517,46 +521,46 @@ class FisheyeImage extends FisheyeBase { $fileHash['name'] = $this->getField( 'file_name' ); $fileHash['thumbnail_sizes'] = $pThumbSizes; // just generate thumbnails - liberty_generate_thumbnails( $fileHash ); + \Bitweaver\Liberty\liberty_generate_thumbnails( $fileHash ); if( !empty( $fileHash['error'] ) ) { $this->mErrors['thumbnail'] = $fileHash['error']; } } - return( count($this->mErrors) == 0 ); + return count($this->mErrors) == 0; } - function getStorageUrl( $pParamHash = array() ) { - $pParamHash['sub_dir'] = $this->getParameter( $pParamHash, 'sub_dir', liberty_mime_get_storage_sub_dir_name( array( 'type'=>$this->getField( 'mime_type' ), 'name'=>$this->getField('file_name') ) ) ); + public function getStorageUrl( $pParamHash = [] ) { + $pParamHash['sub_dir'] = $this->getParameter( $pParamHash, 'sub_dir', \Bitweaver\Liberty\liberty_mime_get_storage_sub_dir_name( [ 'type'=>$this->getField( 'mime_type' ), 'name'=>$this->getField('file_name') ] ) ); $pParamHash['user_id'] = $this->getParameter( $pParamHash, 'user_id', $this->getField('user_id') ); return parent::getStorageUrl( $pParamHash ).$this->getParameter( $pParamHash, 'attachment_id', $this->getField('attachment_id') ).'/'; } - function getStorageBranch( $pParamHash = array() ) { - $pParamHash['sub_dir'] = $this->getParameter( $pParamHash, 'sub_dir', liberty_mime_get_storage_sub_dir_name( array( 'type'=>$this->getField( 'mime_type' ), 'name'=>$this->getField('file_name') ) ) ); + public function getStorageBranch( $pParamHash = [] ) { + $pParamHash['sub_dir'] = $this->getParameter( $pParamHash, 'sub_dir', \Bitweaver\Liberty\liberty_mime_get_storage_sub_dir_name( [ 'type'=>$this->getField( 'mime_type' ), 'name'=>$this->getField('file_name') ] ) ); $pParamHash['user_id'] = $this->getParameter( $pParamHash, 'user_id', $this->getField('user_id') ); return parent::getStorageBranch( $pParamHash ).$this->getParameter( $pParamHash, 'attachment_id', $this->getField('attachment_id') ).'/'; } - function getStoragePath( $pParamHash, $pRootDir=NULL ) { - $pParamHash['sub_dir'] = liberty_mime_get_storage_sub_dir_name( array( 'type'=>BitBase::getParameter( $pParamHash, 'mime_type', $this->getField( 'mime_type' ) ), 'name'=>BitBase::getParameter( $pParamHash, 'file_name', $this->getField('file_name') ) ) ); + public function getStoragePath( $pParamHash, $pRootDir=null ) { + $pParamHash['sub_dir'] = \Bitweaver\Liberty\liberty_mime_get_storage_sub_dir_name( [ 'type'=>BitBase::getParameter( $pParamHash, 'mime_type', $this->getField( 'mime_type' ) ), 'name'=>BitBase::getParameter( $pParamHash, 'file_name', $this->getField('file_name') ) ] ); $pParamHash['user_id'] = $this->getParameter( $pParamHash, 'user_id', $this->getField('user_id') ); return parent::getStoragePath( $pParamHash ).$this->getParameter( $pParamHash, 'attachment_id', $this->getField('attachment_id') ).'/'; } - function getPreviewHash() { + public function getPreviewHash() { return $this->mInfo; } // Get resolution, etc - function getImageDetails($pFilePath = NULL) { - $info = array(); - if( file_exists( $pFilePath ) ) { - $checkFiles = array( $pFilePath, dirname( $pFilePath ).'/original.jpg' ); + public function getImageDetails($pFilePath = null) { + $info = []; + if( file_exists( $pFilePath ?? '' ) ) { + $checkFiles = [ $pFilePath, dirname( $pFilePath ).'/original.jpg' ]; } else { $sourceFile = $this->getSourceFile(); - $checkFiles = array( $sourceFile ); + $checkFiles = [ $sourceFile ]; // was an original file created? - $originalFile = dirname( $sourceFile ).'/original.jpg'; + $originalFile = dirname( $sourceFile ?? '' ).'/original.jpg'; if( file_exists( $originalFile ) && !is_link( $originalFile ) ) { $checkFiles[] = $originalFile; } @@ -576,14 +580,14 @@ class FisheyeImage extends FisheyeBase { return $info; } - function getWidth() { + public function getWidth() { if( !isset( $this->mInfo['width'] ) ) { $this->mInfo = array_merge( $this->mInfo, $this->getImageDetails() ); } return $this->getField('width'); } - function getHeight() { + public function getHeight() { if( !isset( $this->mInfo['width'] ) ) { $this->mInfo = array_merge( $this->mInfo, $this->getImageDetails() ); } @@ -592,32 +596,31 @@ class FisheyeImage extends FisheyeBase { /** * Returns include file that will setup vars for display - * @return the fully specified path to file to be included + * @return string the fully specified path to file to be included */ - function getRenderFile() { + public function getRenderFile() { return FISHEYE_PKG_INCLUDE_PATH.'display_fisheye_image_inc.php'; } /** * Returns template file used for display - * @return the fully specified path to file to be included + * @return string the fully specified path to file to be included */ - function getRenderTemplate() { + public function getRenderTemplate() { return 'bitpackage:fisheye/view_image.tpl'; } /** * Function that returns link to display a piece of content - * @param pImageId id of gallery to link - * @param pParamHash if a string, it is assumed to be the size, if an array, it is assumed to be a mInfo hash - * @return the url to display the gallery. + * @param array pParamHash if a string, it is assumed to be the size, if an array, it is assumed to be a mInfo hash + * @return string the url to display the gallery. */ public static function getDisplayUrlFromHash( &$pParamHash ) { $ret = ''; - $size = (!empty( $pParamHash['size'] ) && is_string( $pParamHash['size'] ) && isset( $pParamHash['thumbnail_url'][$pParamHash['size']] ) ) ? $pParamHash['size'] : NULL ; + $size = (!empty( $pParamHash['size'] ) && is_string( $pParamHash['size'] ) && isset( $pParamHash['thumbnail_url'][$pParamHash['size']] ) ) ? $pParamHash['size'] : null ; global $gBitSystem; - if( @BitBase::verifyId( $pParamHash['image_id'] ) ) { + if( BitBase::verifyId( $pParamHash['image_id'] ?? 0 ) ) { if( $gBitSystem->isFeatureActive( 'pretty_urls' ) ) { $ret = FISHEYE_PKG_URL.'image/'.$pParamHash['image_id']; if( !empty( $pParamHash['gallery_path'] ) ) { @@ -628,14 +631,14 @@ class FisheyeImage extends FisheyeBase { } } else { $ret = FISHEYE_PKG_URL.'view_image.php?image_id='.$pParamHash['image_id']; - if( !empty( $this ) && !empty( $pParamHash['gallery_path'] ) ) { + if( !empty( $pParamHash['gallery_path'] ) ) { $ret .= '&gallery_path='.$pParamHash['gallery_path']; } if( $size ) { $ret .= '&size='.$size; } } - } elseif( @BitBase::verifyId( $pParamHash['content_id'] ) ) { + } elseif ( BitBase::verifyId( $pParamHash['content_id'] ?? 0 ) ) { $ret = FISHEYE_PKG_URL.'view_image.php?content_id='.$pParamHash['content_id']; } return $ret; @@ -643,34 +646,35 @@ class FisheyeImage extends FisheyeBase { /** * Function that returns link to display an image - * @return the url to display the gallery. + * @return string the url to display the gallery. */ public function getDisplayUrl() { $info = &$this->mInfo; $info['image_id'] = $this->mImageId; $info['gallery_path'] = $this->mGalleryPath; - return static::getDisplayUrlFromHash( $info ); + return FisheyeImage::getDisplayUrlFromHash( $info ); } /** * Function that returns link to display an image * Used to display thumbnails for navigation bar - * @param pImageId id of image to link - * @return the url to display the image. + * @param array pImageId id of image to link + * @return string the url to display the image. */ public function getImageUrl( $pImageId ) { - $info = array( 'image_id' => $pImageId ); - return static::getDisplayUrlFromHash( $info ); + $info = [ 'image_id' => $pImageId ]; + return FisheyeImage::getDisplayUrlFromHash( $info ); } /** * Generate a valid display link for the Blog * - * @param object PostId of the item to use + * @param array PostId of the item to use + * @param string Image Title * @param array Not used - * @return object Fully formatted html link for use by Liberty + * @return string Fully formatted html link for use by Liberty */ - static function getDisplayLinkFromHash( &$pParamHash, $pTitle=NULL, $pAnchor=NULL ) { + public static function getDisplayLinkFromHash( &$pParamHash, $pTitle=null, $pAnchor=null ) { global $gBitSystem; $pTitle = trim( $pTitle ); @@ -686,10 +690,10 @@ class FisheyeImage extends FisheyeBase { return $ret; } - static public function getTitleFromHash( &$pHash, $pDefault=TRUE ) { + public static function getTitleFromHash( &$pHash, $pDefault=true ) { $ret = trim( parent::getTitleFromHash( $pHash, $pDefault ) ); if( empty( $ret ) && $pDefault ) { - $storage = (!empty( $this ) && !empty( $this->mStorage ) ? current( $this->mStorage ) : NULL); + $storage = []; // !empty( $this ) && !empty( $this->mStorage ) ? current( $this->mStorage ) : null; if( !empty( $storage['file_name'] ) ) { $ret = $storage['file_name']; } else { @@ -704,7 +708,7 @@ class FisheyeImage extends FisheyeBase { } public function getTitle() { - $ret = NULL; + $ret = null; if( $this->isValid() ) { $ret = self::getTitleFromHash( $this->mInfo ); } @@ -712,69 +716,70 @@ class FisheyeImage extends FisheyeBase { } - function getThumbnailContentId() { - return( $this->mContentId ); + public function getThumbnailContentId() { + return $this->mContentId; } - function getThumbnailUrl( $pSize = 'small', $pInfoHash = NULL, $pSecondaryId = NULL, $pDefault=TRUE ) { - $ret = NULL; + public function getThumbnailUrl( string $pSize = 'small', ?array $pInfoHash = null, ?int $pSecondaryId = null, ?int $pDefault = null ): string|null { + $ret = null; if( $this->isValid() && isset( $this->mInfo['thumbnail_url'][$pSize] ) ) { $ret = $this->mInfo['thumbnail_url'][$pSize]; } return $ret; } - public static function getThumbnailUrlFromHash( &$pParamHash, $pSize = 'small', $pSecondaryId = NULL, $pDefault=TRUE ) { - $ret = NULL; + public static function getThumbnailUrlFromHash( array &$pParamHash, string $pSize = 'small', ?int $pSecondaryId = -2, ?int $pDefault = -2 ): string { + $ret = ''; if( isset( $pParamHash['thumbnail_url'][$pSize] ) ) { $ret = $pParamHash['thumbnail_url'][$pSize]; } return $ret; } - function expunge($pExpungeAttachment = TRUE) { + public function expunge(): bool { if( $this->isValid() ) { $this->StartTrans(); $query = "DELETE FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE `item_content_id` = ?"; - $rs = $this->mDb->query($query, array( $this->mContentId )); - $query = "UPDATE `".BIT_DB_PREFIX."fisheye_gallery` SET `preview_content_id`=NULL WHERE `preview_content_id` = ?"; - $rs = $this->mDb->query($query, array( $this->mContentId )); + $rs = $this->mDb->getOne($query, [ $this->mContentId ] ); + $query = "UPDATE `".BIT_DB_PREFIX."fisheye_gallery` SET `preview_content_id`=null WHERE `preview_content_id` = ?"; + $rs = $this->mDb->getOne($query, [ $this->mContentId ] ); $query = "DELETE FROM `".BIT_DB_PREFIX."fisheye_image` WHERE `content_id` = ?"; - $rs = $this->mDb->query($query, array( $this->mContentId )); - if( LibertyMime::expunge($pExpungeAttachment) ) { + $rs = $this->mDb->getOne($query, [ $this->mContentId ] ); + if( LibertyMime::expunge() ) { $this->CompleteTrans(); - $this->mImageId = NULL; - $this->mContentId = NULL; + $this->mImageId = null; + $this->mContentId = null; } else { $this->mDb->RollbackTrans(); } } - return( count( $this->mErrors ) == 0 ); + return true; } - function expungingAttachment($pAttachmentId, $pContentIdArray) { + public function expungingAttachment($pAttachmentId, $pContentIdArray) { foreach ($pContentIdArray as $id) { $this->mContentId = $id; // Vital that we call LibertyMime::expunge with false since the attachment is already being deleted. - $this->expunge(FALSE); + // TODO This needs fixing as LibertyMime does not have that option + $this->expunge(); } } - function isValid() { - return( @$this->verifyId( $this->mImageId ) || @$this->verifyId( $this->mContentId ) ); + public function isValid() { + return @$this->verifyId( $this->mImageId ) || @$this->verifyId( $this->mContentId ); } - function imageExistsInDatabase() { - $ret = FALSE; + public function imageExistsInDatabase() { + $ret = false; if( $this->isValid() && $this->mImageId ) { $query = "SELECT COUNT(`image_id`) FROM `".BIT_DB_PREFIX."fisheye_image` WHERE `image_id` = ?"; - $bindVars = array($this->mImageId); + $bindVars = [ $this->mImageId ]; if($this->mDb->getOne($query, $bindVars) > 0){ - $ret = TRUE; + $ret = true; } } @@ -782,18 +787,17 @@ class FisheyeImage extends FisheyeBase { } - function getList( &$pListHash ) { + public function getList( &$pListHash ) { global $gBitUser,$gBitSystem; LibertyContent::prepGetList( $pListHash ); - - $ret = $bindVars = array(); + $ret = $bindVars = []; $distinct = ''; $select = ''; $whereSql = ''; $joinSql = ''; - if( @$this->verifyId( $pListHash['user_id'] ) ) { + if( @$this->verifyId( $pListHash['user_id'] ?? 0 ) ) { $whereSql .= " AND lc.`user_id` = ? "; $bindVars[] = $pListHash['user_id']; } elseif( !empty( $pListHash['recent_users'] )) { @@ -801,7 +805,7 @@ class FisheyeImage extends FisheyeBase { $pListHash['sort_mode'] = 'uu.user_id_desc'; } - if( @$this->verifyId( $pListHash['gallery_id'] ) ) { + if( @$this->verifyId( $pListHash['gallery_id'] ?? 0 ) ) { $whereSql .= " AND fg.`gallery_id` = ? "; $bindVars[] = $pListHash['gallery_id']; } @@ -834,7 +838,7 @@ class FisheyeImage extends FisheyeBase { $whereSql = substr_replace( $whereSql, ' WHERE ', 0, 4 ); } - $thumbSize = (!empty( $pListHash['size'] ) ? $pListHash['size'] : 'avatar' ); + $thumbSize = !empty( $pListHash['size'] ) ? $pListHash['size'] : 'avatar'; $query = "SELECT $distinct fi.`image_id` AS `hash_key`, fi.*, lf.*, la.attachment_id, lc.*, fg.`gallery_id`, uu.`login`, uu.`real_name` $select $selectSql FROM `".BIT_DB_PREFIX."fisheye_image` fi @@ -845,22 +849,23 @@ class FisheyeImage extends FisheyeBase { LEFT OUTER JOIN `".BIT_DB_PREFIX."fisheye_gallery_image_map` tfgim2 ON(tfgim2.`item_content_id`=lc.`content_id`) LEFT OUTER JOIN `".BIT_DB_PREFIX."fisheye_gallery` fg ON(fg.`content_id`=tfgim2.`gallery_content_id`) $whereSql $orderby"; - if( $rs = $this->mDb->query( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'], $pListHash['query_cache_time'] ) ) { - while( $row = $rs->fetchRow() ) { + if( $rows = $this->mDb->getAssoc( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'], $pListHash['query_cache_time'] ) ) { + foreach( $rows as $row ) { // legacy table data was named storage_path and included a partial path. strip out any path just in case + $row['hash_key'] = $row['image_id']; $row['file_name'] = basename( $row['file_name'] ); $ret[$row['hash_key']] = $row; $imageId = $row['image_id']; if( empty( $pListHash['no_thumbnails'] ) ) { $ret[$imageId]['display_url'] = static::getDisplayUrlFromHash( $row ); - $ret[$imageId]['has_machine_name'] = $this->isMachineName( $ret[$imageId]['title'] ); - $ret[$imageId]['source_url'] = liberty_mime_get_storage_url( $row ).$row['file_name']; - $ret[$imageId]['thumbnail_url'] = liberty_fetch_thumbnail_url( array( +// $ret[$imageId]['has_machine_name'] = $this->isMachineName( $ret[$imageId]['title'] ); + $ret[$imageId]['source_url'] = \Bitweaver\Liberty\liberty_mime_get_storage_url( $row ).$row['file_name']; + $ret[$imageId]['thumbnail_url'] = \Bitweaver\Liberty\liberty_fetch_thumbnail_url( [ 'source_file' => $this->getSourceFile( $row ), 'default_image' => FISHEYE_PKG_URL.'image/generating_thumbnails.png', 'size' => $thumbSize, 'type' => $row['mime_type'], - )); + ] ); } } } @@ -871,9 +876,9 @@ class FisheyeImage extends FisheyeBase { * isCommentable * * @access public - * @return TRUE on success, FALSE on failure + * @return bool true on success, false on failure */ - function isCommentable() { + public function isCommentable() { global $gGallery; // if we have a loaded gallery, we just use that to work out if we can add comments to this image @@ -881,13 +886,13 @@ class FisheyeImage extends FisheyeBase { return $gGallery->isCommentable(); } - $ret = FALSE; + $ret = false; if( $parents = $this->getParentGalleries() ) { // @TODO: No idea how to work out if you can add a comment to this image // for now we'll take the mGalleryPath and use that gallery $gal = current( $parents ); $query = "SELECT `pref_value` FROM `".BIT_DB_PREFIX."liberty_content_prefs` WHERE `content_id` = ? AND `pref_name` = ?"; - $ret = ( $this->mDb->getOne( $query, array( $gal['content_id'], 'allow_comments' )) == 'y' ); + $ret = $this->mDb->getOne( $query, [ $gal['content_id'], 'allow_comments' ] ) == 'y'; } return $ret; } @@ -895,6 +900,4 @@ class FisheyeImage extends FisheyeBase { public static function getServiceKey() { return 'fisheye'; } -} - -?> +}
\ No newline at end of file diff --git a/includes/classes/FisheyeRemote.php b/includes/classes/FisheyeRemote.php index ec69114..d4da14e 100644..100755 --- a/includes/classes/FisheyeRemote.php +++ b/includes/classes/FisheyeRemote.php @@ -20,6 +20,12 @@ // | Authors: spider <spider@steelsun.com> // +----------------------------------------------------------------------+ +/** + * required setup + */ +namespace Bitweaver\Fisheye; +use Bitweaver\KernelTools; + define( 'FEG2REMOTE_SUCCESS', 0 ); define( 'FEG2REMOTE_PROTOCOL_MAJOR_VERSION_INVALID', 101 ); @@ -49,18 +55,18 @@ define( 'FEG2REMOTE_ROTATE_IMAGE_FAILED', 504 ); */ class FisheyeRemote { - public $mResponse = array(); + public $mResponse = []; public $mSubGalIdx = 1; - function getApiVersion() { + public function getApiVersion() { return '2.14'; } // separate out pPostData and pParamhash data since some plugins can populate _POST['g2_form'] and _GET['g2_form'] differently. // weird but true. ubermind is an example - function processRequest( $pGetData, $pPostData ) { + public function processRequest( $pGetData, $pPostData ) { $pData = array_merge($pGetData, $pPostData); //Some programs (galleryexport) pass both post and get...and the cmd can be in either get or post if(!empty($pData)){ @@ -124,43 +130,42 @@ class FisheyeRemote { } - function cmdNoOp( $pParamHash ) { + public function cmdNoOp( $pParamHash ) { global $gBitUser; $response = $this->createResponse( FEG2REMOTE_SUCCESS, 'No-op successful' ); return $response; } - function cmdLogin( $pParamHash ) { + public function cmdLogin( $pParamHash ) { global $gBitUser, $gBitSystem; $url = $gBitUser->login( $pParamHash['uname'], $pParamHash['password'] ); - if( $gBitUser->isRegistered() ) { + $response = $gBitUser->isRegistered() /* $cookieTime = ( int )( time() + $gBitSystem->getConfig( 'users_remember_time', 86400 )); $cookiePath = $gBitSystem->getConfig( 'cookie_path', BIT_ROOT_URL ); $cookieDomain = $gBitSystem->getConfig( 'cookie_domain', "" ); setcookie( 'GALLERYSID', session_id(), $cookieTime, $cookiePath, $cookieDomain ); */ - $response = $this->createResponse( FEG2REMOTE_SUCCESS, 'Login successful.', array( 'server_version' => $this->getApiVersion() ) ); - } else { - $response = $this->createResponse( FEG2REMOTE_PASSWORD_WRONG, 'Invalid username or password' ); - } + ? $this->createResponse( FEG2REMOTE_SUCCESS, 'Login successful.', [ 'server_version' => $this->getApiVersion() ] ) + : $this->createResponse( FEG2REMOTE_PASSWORD_WRONG, 'Invalid username or password' ); + return $response; } // Recursively traverses a multi-dimensional array of galleries - function traverseGalleries( &$pGalHash, &$pResponse ) { + public function traverseGalleries( &$pGalHash, &$pResponse ) { global $gBitUser; // Albums don't like being 0 indexed $this->mSubGalIdx = 0; // the lightroom client is dumb, and can only handle one 0 level parent - if( stripos( $_SERVER['HTTP_USER_AGENT'], 'lightroom' ) !== FALSE ) { + if( stripos( $_SERVER['HTTP_USER_AGENT'], 'lightroom' ) !== false ) { $this->mSubGalIdx++; $pResponse['album.parent.' . $this->mSubGalIdx] = 0; $pResponse['album.name.' . $this->mSubGalIdx] = 1; - $pResponse['album.title.' . $this->mSubGalIdx] = tra( 'Select a Gallery' ); + $pResponse['album.title.' . $this->mSubGalIdx] = KernelTools::tra( 'Select a Gallery' ); $pResponse['album.perms.add.' . $this->mSubGalIdx] = 'false'; $pResponse['album.perms.write.' . $this->mSubGalIdx] = 'false'; $pResponse['album.perms.del_alb.' . $this->mSubGalIdx] = 'false'; @@ -175,27 +180,22 @@ class FisheyeRemote { * @param $pGalHash branch of gallery information from FisheyeGallery::getTree * @param $pResponse aggregate string containing response array * @param $pParentRandom depth of pGalHash - this is used to non-definitively uniquify album.parent and album.name entries - * @return the url to display the gallery. + * @return string the url to display the gallery. */ - function traverseSubGalleries( &$pGalHash, &$pResponse, $pParentRandom ) { + public function traverseSubGalleries( &$pGalHash, &$pResponse, $pParentRandom ) { global $gBitUser; foreach( $pGalHash as $key=>$gallery) { $this->mSubGalIdx++; // Any number greater than 2 digits crashes iPhoto2Gallery $randomizer = str_pad( rand( 1, 99 ), 2, '0' ); - if($gallery['content']['level'] != 0){ + $pResponse['album.parent.' . $this->mSubGalIdx] = $gallery['content']['level'] != 0 // Fisheye allows directories to below to multiple parents - not in gallery. This confuses some clients // We pad with a random number for uniqueness - $pResponse['album.parent.' . $this->mSubGalIdx] = $gallery['content']['cb_gallery_content_id'].$pParentRandom; - } else { + ? $gallery['content']['cb_gallery_content_id'].$pParentRandom // the lightroom client is dumb, and can only handle one 0 level parent - if( stripos( $_SERVER['HTTP_USER_AGENT'], 'lightroom' ) !== FALSE ) { - $pResponse['album.parent.' . $this->mSubGalIdx] = 1; - } else { - $pResponse['album.parent.' . $this->mSubGalIdx] = 0; - } - } + : ( stripos( $_SERVER['HTTP_USER_AGENT'], 'lightroom' ) !== false ? 1 : 0); + // append pParentRandom to make .name probably unique since Fisheye can handle one gallery linked to multiple parents $pResponse['album.name.' . $this->mSubGalIdx] = $gallery['content']['content_id'].$randomizer; $pResponse['album.title.' . $this->mSubGalIdx] = $this->cleanResponseValue( $gallery['content']['title'] ); @@ -218,21 +218,21 @@ class FisheyeRemote { return $ret; } - function cmdFetchAlbums( $pParamHash ) { - require_once( FISHEYE_PKG_CLASS_PATH.'FisheyeGallery.php' ); + public function cmdFetchAlbums( $pParamHash ) { + require_once FISHEYE_PKG_CLASS_PATH.'FisheyeGallery.php'; global $gBitUser; if( $gBitUser->isRegistered() ) { $treeGallery = new FisheyeGallery(); $listHash['user_id'] = $gBitUser->mUserId; - if( $galleryList = $treeGallery->getTree( $listHash, array( 'name' => "gallery_id", 'id' => "gallerylist", 'item_attributes' => array( 'class'=>'listingtitle' ) ) ) ) { - $galResponse = array(); + if( $galleryList = $treeGallery->getTree( [ $listHash, 'name' => "gallery_id", 'id' => "gallerylist", 'item_attributes' => [ 'class'=>'listingtitle' ] ] ) ) { + $galResponse = []; $galleryCount = $this->traverseGalleries( $galleryList, $galResponse ); $galResponse['album_count'] = $galleryCount; $galResponse['can_create_root'] = 'true'; $response = $this->createResponse( FEG2REMOTE_SUCCESS, 'Gallery list successful', $galResponse ); } else { // perhaps we should make at least on gallery at this point? - $response = $this->createResponse( FEG2REMOTE_SUCCESS, 'No galleries', array( 'album_count' => 0 ) ); + $response = $this->createResponse( FEG2REMOTE_SUCCESS, 'No galleries', [ 'album_count' => 0 ] ); } } else { $response = $this->createResponse( FEG2REMOTE_PASSWORD_WRONG, 'Application not logged in' ); @@ -241,40 +241,38 @@ class FisheyeRemote { } - function cmdAddItem( $pParamHash ) { - $response = array(); + public function cmdAddItem( $pParamHash ) { + $response = []; - $uploadFile = (!empty( $_FILES['g2_userfile'] ) ? $_FILES['g2_userfile'] : NULL); + $uploadFile = !empty( $_FILES['g2_userfile'] ) ? $_FILES['g2_userfile'] : null; if( empty( $pParamHash['set_albumName'] ) ) { - $response = $this->createResponse( CREATE_ALBUM_FAILED , 'No gallery specified' ); + $response = $this->createResponse( FEG2REMOTE_CREATE_ALBUM_FAILED , 'No gallery specified' ); } elseif( empty( $uploadFile ) || empty( $uploadFile['size'] ) ) { $response = $this->createResponse( FEG2REMOTE_NO_FILENAME, 'No image uploaded' ); } else { - $storeHash['title'] = !empty( $pParamHash['force_filename'] ) ? $pParamHash['force_filename'] : NULL; - $storeHash['summary'] = !empty( $pParamHash['extrafield.Summary'] ) ? $pParamHash['extrafield.Summary'] : NULL; - $storeHash['edit'] = !empty( $pParamHash['extrafield.Description'] ) ? $pParamHash['extrafield.Description'] : NULL; + $storeHash['title'] = !empty( $pParamHash['force_filename'] ) ? $pParamHash['force_filename'] : null; + $storeHash['summary'] = !empty( $pParamHash['extrafield.Summary'] ) ? $pParamHash['extrafield.Summary'] : null; + $storeHash['edit'] = !empty( $pParamHash['extrafield.Description'] ) ? $pParamHash['extrafield.Description'] : null; - require_once (FISHEYE_PKG_INCLUDE_PATH.'upload_inc.php'); + require_once FISHEYE_PKG_INCLUDE_PATH.'upload_inc.php'; $parentGallery = new FisheyeGallery(); - if( $parentGallery = $parentGallery->lookup(array('content_id' => $pParamHash['set_albumName'] ) ) ) { + if( $parentGallery = $parentGallery->lookup([ 'content_id' => $pParamHash['set_albumName'] ] ) ) { $parentGallery->load(); - $storeHash['gallery_additions'] = array($parentGallery->mGalleryId); - } - if( $errors = fisheye_store_upload( $uploadFile , $storeHash ) ){ - $response = $this->createResponse( FEG2REMOTE_UPLOAD_PHOTO_FAIL, 'Export Failed' ); - } else { - $response = $this->createResponse( FEG2REMOTE_SUCCESS, 'Image added', array( 'item_name'=>$uploadFile['name'] ) ); + $storeHash['gallery_additions'] = [ $parentGallery->mGalleryId ]; } + $response = $errors = fisheye_store_upload( $uploadFile , $storeHash ) + ? $response = $this->createResponse( FEG2REMOTE_UPLOAD_PHOTO_FAIL, 'Export Failed' ) + : $this->createResponse( FEG2REMOTE_SUCCESS, 'Image added', [ 'item_name'=>$uploadFile['name'] ] ); } return $response; } - function cmdNewAlbum( $pParamHash ) { + public function cmdNewAlbum( $pParamHash ) { global $gBitUser; - $response = array(); + $response = []; if( empty( $pParamHash['newAlbumTitle'] ) ) { $pParamHash['newAlbumTitle'] = $gBitUser->getTitle()."'s Gallery"; @@ -287,18 +285,18 @@ class FisheyeRemote { if($pParamHash['set_albumName']){ $parentGallery = new FisheyeGallery(); - if( $parentGallery = $parentGallery->lookup(array('content_id' => $pParamHash['set_albumName'] ) ) ) { + if( $parentGallery = $parentGallery->lookup(['content_id' => $pParamHash['set_albumName'] ] ) ) { $parentGallery->load(); - $gallery->addToGalleries(array($parentGallery->mGalleryId)); + $gallery->addToGalleries([ $parentGallery->mGalleryId ] ); } } - $response = $this->createResponse( FEG2REMOTE_SUCCESS, 'Gallery created', array( 'album_name' => $storeHash['title'] ) ); + $response = $this->createResponse( FEG2REMOTE_SUCCESS, 'Gallery created', [ 'album_name' => $storeHash['title'] ] ); return $response; } - function sendResponse( $pResponse ) { + public function sendResponse( $pResponse ) { global $gBitUser; print "#__GR2PROTO__\n"; //error_log( "#__GR2PROTO__".' : '.$gBitUser->mUserId ); @@ -313,13 +311,13 @@ class FisheyeRemote { } - function createResponse( $pStatus, $pStatusText, $pExtra = NULL ) { - $ret = array(); + public function createResponse( $pStatus, $pStatusText, $pExtra = null ) { + $ret = []; // Each response must contain at least the keys: status and status_text. $ret['status'] = $this->cleanResponseValue( $pStatus ); // translate the text response for i18n - $ret['status_text'] = $this->cleanResponseValue( tra( $pStatusText ) ); + $ret['status_text'] = $this->cleanResponseValue( KernelTools::tra( $pStatusText ) ); // tack on any additional responses if( !empty( $pExtra ) && is_array( $pExtra ) ) { foreach( $pExtra as $k => $value ) { @@ -334,17 +332,17 @@ class FisheyeRemote { * Gallery apparently is very particular about the manner in which this data is cleaned up, and must be done * in this specific order. */ - function cleanResponseValue( $pValue ) { + public function cleanResponseValue( $pValue ) { $pValue = str_replace('\\', '\\\\', $pValue); $pValue = str_replace("\r\n", '\n', $pValue); - $pValue = str_replace(array("\r", "\n", "\t"), array('\n', '\n', '\t'), $pValue); - $pValue = str_replace(array('#', '!', '='), array('\\#', '\\!', '\\='), $pValue); + $pValue = str_replace([ "\r", "\n", "\t" ], [ '\n', '\n', '\t' ], $pValue); + $pValue = str_replace([ '#', '!', '=' ], [ '\\#', '\\!', '\\=' ], $pValue); return $pValue; } - function cleanResponseKey( $pKey ) { - return str_replace(array('#', '!', '=', ':'), array('\\#', '\\!', '\\=', '\\:'), $pKey); + public function cleanResponseKey( $pKey ) { + return str_replace([ '#', '!', '=', ':' ], [ '\\#', '\\!', '\\=', '\\:' ], $pKey); } |
