/
TreasuryBase.php
167 lines (156 loc) · 5.13 KB
/
TreasuryBase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* @version $Header$
*
* @author xing <xing@synapse.plus.com>
* @version $Revision$
* created Monday Jul 03, 2006 11:01:55 CEST
* @package treasury
* @copyright 2003-2006 bitweaver
* @license LGPL {@link http://www.gnu.org/licenses/lgpl.html}
**/
/**
* Setup
*/
require_once( LIBERTY_PKG_CLASS_PATH.'LibertyMime.php' );
require_once( LIBERTY_PKG_CLASS_PATH.'LibertyStructure.php' );
/**
* TreasuryBase
*
* @package treasury
* @uses LibertyMime
*/
class TreasuryBase extends LibertyMime {
/**
* Initiates class
*
* @access public
* @return void
*/
function TreasuryBase() {
if( get_class( $this ) == 'treasurygallery' ) {
parent::__construct();
} else {
parent::__construct();
}
}
/**
* Get the path of the gallery
*
* @param numeric $pStructureId ID of the gallery we want to find the path to
* @access public
* @return Gallery path on success, FALSE on failure - mErrors will contain reason for failure
*/
function getGalleryPath( $pStructureId = NULL ) {
if( !@BitBase::verifyId( $pStructureId ) ) {
$pStructureId = $this->mStructureId;
}
if( @BitBase::verifyId( $pStructureId ) ) {
global $gStructure;
// create new object if needed
if( empty( $gStructure ) ) {
$gStructure = new LibertyStructure();
}
// get the structure path
$ret = $gStructure->getPath( $pStructureId );
}
return( !empty( $ret ) ? $ret : FALSE );
}
/**
* Get an HTML representation of the gallery path returned by getGalleryPath()
*
* @param array $pPath Path returned by getGalleryPath()
* @access public
* @return HTML links
*/
function getDisplayPath( $pPath ) {
$ret = "";
if( !empty( $pPath ) && is_array( $pPath ) ) {
$ret .= " » ";
foreach( $pPath as $node ) {
$ret .= ( @BitBase::verifyId( $node['parent_id'] ) ? ' » ' : '' ).'<a title="'.htmlspecialchars( $node['title'] ).'" href="'.TreasuryGallery::getDisplayUrlFromHash( $node ).'">'.htmlspecialchars( $node['title'] ).'</a>';
}
}
return $ret;
}
/**
* Get the last gallery created by this user. If the user hasn't created a gallery, create one
*
* @param string $pNewName Name of the new gallery
* @access public
* @return Gallery Id of the default gallery
*/
function getDefaultGalleryId( $pNewName = NULL ) {
global $gBitUser, $gContent;
// as default gallery, we pick the first one created by this user
$gal = new TreasuryGallery();
$getHash = array( 'user_id' => $gBitUser->mUserId, 'max_records' => 1, 'sort_mode' => 'created_asc' );
$upGal = $gal->getList( $getHash );
if( @BitBase::verifyId( key( $upGal ) ) ) {
$ret = key( $upGal );
} elseif( $gBitUser->hasPermission( 'p_treasury_create_gallery' ) ) {
// Since the user can create a new gallery, we simply create a new one
if( empty( $pNewName ) ) {
$pNewName = $gBitUser->getDisplayName()."'s File Gallery";
}
$galleryHash = array( 'title' => $pNewName );
if( $gal->store( $galleryHash ) ) {
$ret = $gal->mContentId;
}
} else {
// if we reach this section, we'll simply pick the first gallery we can find and dump all files in there
$getHash = array( 'max_records' => 1, 'sort_mode' => 'created_asc' );
$upGal = $gal->getList( $getHash );
if( @BitBase::verifyId( key( $upGal ) ) ) {
$ret = key( $upGal );
} else {
// we need to report that there is absolutely no way we can place the gallery anywhere
$this->mErrors['no_default'] = tra( 'We could not find a viable gallery where we can store your upload' );
}
}
if( !$gContent->isValid() ) {
$gContent = new TreasuryGallery( $ret );
}
return $ret;
}
/**
* Update the position of an item in the gallery
*
* @param numeric $pGalleryContentId Gallery content id of the gallery where we want to move around the order of things
* @param numeric $newPosition New position number
* @access public
* @return void
*/
function updatePosition( $pGalleryContentId, $newPosition = NULL ) {
if( $pGalleryContentId && $newPosition && $this->verifyId( $this->mContentId ) ) {
// SQL optimization to prevent stupid updates of identical data
$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 ) );
}
}
/**
* hasDownloadPermission will mimic hasViewPermission for downloads
*
* @access public
* @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
*/
function hasDownloadPermission() {
return( $this->hasUpdatePermission() || $this->hasUserPermission( 'p_treasury_download_item' ));
}
/**
* verifyDownloadPermission will mimic verifyViewPermission for downloads
*
* @access public
* @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
*/
function verifyDownloadPermission() {
if( $this->hasDownloadPermission() ) {
return TRUE;
} else {
global $gBitSystem;
$gBitSystem->fatalPermission( 'p_treasury_download_item' );
}
}
}
?>