PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/TreasuryGallery.php

https://github.com/tekimaki/treasury
PHP | 614 lines | 397 code | 70 blank | 147 comment | 91 complexity | d5a30abe1ac9d40364c522748d1a4e5e MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Header$
  4. *
  5. * @author xing <xing@synapse.plus.com>
  6. * @version $Revision$
  7. * created Monday Jul 03, 2006 11:53:42 CEST
  8. * @package treasury
  9. * @copyright 2003-2006 bitweaver
  10. * @license LGPL {@link http://www.gnu.org/licenses/lgpl.html}
  11. **/
  12. /**
  13. * Setup
  14. */
  15. define( 'TREASURYGALLERY_CONTENT_TYPE_GUID', 'treasurygallery' );
  16. require_once( TREASURY_PKG_PATH.'TreasuryBase.php' );
  17. /**
  18. * TreasuryGallery
  19. *
  20. * @package treasury
  21. * @uses TreasuryBase
  22. */
  23. class TreasuryGallery extends TreasuryBase {
  24. /**
  25. * If this content is being viewed within a structure
  26. * @public
  27. */
  28. var $mStructureId;
  29. /**
  30. * Initiate class
  31. *
  32. * @param $pContentId content id of the treasury - use either one of the ids.
  33. * @param $pStructureId structure id of the treasury - use either one of the ids.
  34. * @return none
  35. * @access public
  36. **/
  37. function TreasuryGallery( $pStructureId = NULL, $pContentId = NULL ) {
  38. TreasuryBase::TreasuryBase();
  39. $this->registerContentType( TREASURYGALLERY_CONTENT_TYPE_GUID, array(
  40. 'content_type_guid' => TREASURYGALLERY_CONTENT_TYPE_GUID,
  41. 'content_name' => 'File Gallery',
  42. 'content_name_plural' => 'File Galleries',
  43. 'handler_class' => 'TreasuryGallery',
  44. 'handler_package' => 'treasury',
  45. 'handler_file' => 'TreasuryGallery.php',
  46. 'maintainer_url' => 'http://www.bitweaver.org'
  47. ) );
  48. $this->mContentId = $pContentId;
  49. $this->mStructureId = $pStructureId;
  50. $this->mContentTypeGuid = TREASURYGALLERY_CONTENT_TYPE_GUID;
  51. // Permission setup
  52. $this->mViewContentPerm = 'p_treasury_view_gallery';
  53. $this->mCreateContentPerm = 'p_treasury_create_gallery';
  54. $this->mUpdateContentPerm = 'p_treasury_update_gallery';
  55. $this->mAdminContentPerm = 'p_treasury_admin';
  56. }
  57. /**
  58. * load the treasury gallery
  59. *
  60. * @param $pExtras boolean - if set to true, treasury content is added as well
  61. * @return bool TRUE on success, FALSE if it's not valid
  62. * @access public
  63. **/
  64. function load( $pExtras = FALSE ) {
  65. if( @BitBase::verifyId( $this->mContentId ) || @BitBase::verifyId( $this->mStructureId ) ) {
  66. global $gBitSystem;
  67. $lookupColumn = ( @BitBase::verifyId( $this->mContentId ) ? 'lc.`content_id`' : 'ls.`structure_id`' );
  68. $lookupId = ( @BitBase::verifyId( $this->mContentId ) ? $this->mContentId : $this->mStructureId );
  69. $bindVars[] = $lookupId;
  70. $selectSql = $joinSql = $whereSql = '';
  71. $this->getServicesSql( 'content_load_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
  72. $query = "SELECT trg.*, ls.`root_structure_id`, ls.`parent_id`,
  73. lc.`title`, lc.`format_guid`, lc.`data`, lc.`user_id`, lc.`content_type_guid`,
  74. uue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name,
  75. uuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name $selectSql
  76. FROM `".BIT_DB_PREFIX."treasury_gallery` trg
  77. INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( lc.`content_id` = trg.`content_id` )
  78. LEFT JOIN `".BIT_DB_PREFIX."liberty_structures` ls ON ( ls.`structure_id` = trg.`structure_id` )
  79. LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON ( uue.`user_id` = lc.`modifier_user_id` )
  80. LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON ( uuc.`user_id` = lc.`user_id` ) $joinSql
  81. WHERE $lookupColumn = ? $whereSql";
  82. $result = $this->mDb->query( $query, $bindVars );
  83. if( $result && $row = $result->fetchRow() ) {
  84. $this->mInfo = $row;
  85. $this->mContentId = $row['content_id'];
  86. $this->mStructureId = $row['structure_id'];
  87. $this->mInfo['user'] = $row['creator_user'];
  88. $this->mInfo['real_name'] = ( isset( $row['creator_real_name'] ) ? $row['creator_real_name'] : $row['creator_user'] );
  89. $this->mInfo['display_name'] = BitUser::getTitle( $this->mInfo );
  90. $this->mInfo['editor'] = ( isset( $row['modifier_real_name'] ) ? $row['modifier_real_name'] : $row['modifier_user'] );
  91. $this->mInfo['display_url'] = $this->getDisplayUrl();
  92. $this->mInfo['thumbnail_url'] = liberty_fetch_thumbnails( array(
  93. 'storage_path' => $this->getGalleryThumbBaseUrl(),
  94. 'mime_image' => FALSE
  95. ));
  96. // get extra information if required
  97. if( $pExtras ) {
  98. $this->mInfo['gallery_path'] = $this->getGalleryPath();
  99. $this->mInfo['gallery_display_path'] = $this->getDisplayPath( $this->mInfo['gallery_path'] );
  100. }
  101. LibertyContent::load();
  102. // parse the data after parent load so we have our html prefs
  103. $this->mInfo['parsed_data'] = $this->parseData();
  104. }
  105. }
  106. return( count( $this->mInfo ) );
  107. }
  108. /**
  109. * Load all uploaded items in this gallery
  110. *
  111. * @param array $pListHash ListHash is passed on to TreasuryItem::getList();
  112. * @access public
  113. * @return TRUE on success, FALSE on failure - populates $this->mItems
  114. */
  115. function loadItems( &$pListHash ) {
  116. $ret = FALSE;
  117. if( $this->isValid() ) {
  118. require_once( TREASURY_PKG_PATH.'TreasuryItem.php');
  119. $treasuryItem = new TreasuryItem();
  120. if( empty( $pListHash['gallery_content_id'] ) ) {
  121. $pListHash['gallery_content_id'] = $this->mContentId;
  122. }
  123. if( $this->mItems = $treasuryItem->getList( $pListHash, $this->mStructureId )) {
  124. $ret = TRUE;
  125. } elseif( !empty( $treasuryItem->mErrors )) {
  126. error_log( "Error loading treasury items: ".vc( $treasuryItem->mErrors ));
  127. }
  128. }
  129. return $ret;
  130. }
  131. /**
  132. * Get list of all treasury galleries
  133. *
  134. * @param $pListHash contains array of items used to limit search results
  135. * @param $pListHash[sort_mode] column and orientation by which search results are sorted
  136. * @param $pListHash[find] search for a gallery title - case insensitive
  137. * @param $pListHash[max_records] maximum number of rows to return
  138. * @param $pListHash[offset] number of results data is offset by
  139. * @param $pListHash[title] gallery name
  140. * @param $pListHash[parent_id] gallery parent_id
  141. * @param $pListHash[get_sub_tree] get the subtree to every gallery
  142. * @access public
  143. * @return List of galleries
  144. **/
  145. function getList( &$pListHash ) {
  146. global $gBitDbType, $gBitSystem, $gBitUser;
  147. LibertyContent::prepGetList( $pListHash );
  148. $ret = $bindVars = array();
  149. $selectSql = $joinSql = $orderSql = $whereSql = '';
  150. if( @BitBase::verifyId( $pListHash['root_structure_id'] ) ) {
  151. $whereSql .= empty( $whereSql ) ? ' WHERE ' : ' AND ';
  152. $whereSql .= " ls.`root_structure_id`=? ";
  153. $bindVars[] = $pListHash['root_structure_id'];
  154. }
  155. if( !empty( $pListHash['get_sub_tree'] ) ) {
  156. $whereSql .= empty( $whereSql ) ? ' WHERE ' : ' AND ';
  157. $whereSql .= " ls.`structure_id`=ls.`root_structure_id` ";
  158. }
  159. if( !empty( $pListHash['find'] ) ) {
  160. $whereSql .= empty( $whereSql ) ? ' WHERE ' : ' AND ';
  161. $whereSql .= " UPPER( lc.`title` ) LIKE ? ";
  162. $bindVars[] = '%'.strtoupper( $pListHash['find'] ).'%';
  163. }
  164. if ( isset( $pListHash['parent_id'] ) ) {
  165. $whereSql .= empty( $whereSql ) ? ' WHERE ' : ' AND ';
  166. $whereSql .= ' ls.`parent_id` = ? ';
  167. $bindVars[] = $pListHash['parent_id'];
  168. }
  169. if( !empty( $pListHash['sort_mode'] ) ) {
  170. $orderSql .= " ORDER BY ".$this->mDb->convertSortmode( $pListHash['sort_mode'] )." ";
  171. } else {
  172. // default sort mode makes list look nice
  173. $orderSql .= " ORDER BY ls.`root_structure_id`, ls.`structure_id` ASC";
  174. }
  175. // update query with service sql
  176. $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
  177. // get the number of files in this gallery
  178. if( $gBitDbType != 'mysql' && $gBitDbType != 'mysqli' ) {
  179. $subselect = ", (
  180. SELECT COUNT( trm.`item_content_id` )
  181. FROM `".BIT_DB_PREFIX."treasury_map` trm
  182. WHERE trm.`gallery_content_id`=trg.`content_id`
  183. ) AS item_count";
  184. } else {
  185. $subselect = "";
  186. }
  187. // don't fetch trg.`is_private` for list, because it conflicts with gks.is_private
  188. // and it's not used on list anyway
  189. $query = "
  190. SELECT trg.`content_id`, trg.`structure_id`,
  191. ls.`root_structure_id`, ls.`parent_id`,
  192. lc.`title`, lc.`data`, lc.`user_id`, lc.`content_type_guid`, lc.`created`, lc.`format_guid`, lch.`hits`,
  193. uue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name,
  194. uuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name $subselect $selectSql
  195. FROM `".BIT_DB_PREFIX."treasury_gallery` trg
  196. INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( lc.`content_id` = trg.`content_id` )
  197. LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` lch ON ( lc.`content_id` = lch.`content_id` )
  198. LEFT OUTER JOIN `".BIT_DB_PREFIX."users_users` uue ON ( uue.`user_id` = lc.`modifier_user_id` )
  199. LEFT OUTER JOIN `".BIT_DB_PREFIX."users_users` uuc ON ( uuc.`user_id` = lc.`user_id` )
  200. INNER JOIN `".BIT_DB_PREFIX."liberty_structures` ls ON ( ls.`structure_id` = trg.`structure_id` )
  201. $joinSql
  202. $whereSql
  203. $orderSql";
  204. $result = $this->mDb->query( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] );
  205. if( !empty( $pListHash['get_sub_tree'] ) ) {
  206. $struct = new LibertyStructure();
  207. }
  208. while( $aux = $result->fetchRow() ) {
  209. $hasUserPerm = TRUE;
  210. // check to see if we have premissions to do someing specific with this gallery
  211. if( !empty( $pListHash['content_permission'] ) ) {
  212. $gal = new TreasuryGallery( NULL, $aux['content_id'] );
  213. if( !$gal->hasUserPermission( $pListHash['content_permission'] )) {
  214. $hasUserPerm = FALSE;
  215. }
  216. }
  217. if( $hasUserPerm ) {
  218. $content_ids[] = $aux['content_id'];
  219. $aux['user'] = $aux['creator_user'];
  220. $aux['real_name'] = ( isset( $aux['creator_real_name'] ) ? $aux['creator_real_name'] : $aux['creator_user'] );
  221. $aux['editor'] = ( isset( $aux['modifier_real_name'] ) ? $aux['modifier_real_name'] : $aux['modifier_user'] );
  222. $aux['display_name'] = BitUser::getTitle( $aux );
  223. $aux['display_url'] = $this->getDisplayUrl( $aux['content_id'] );
  224. $aux['display_link'] = $this->getDisplayLink( $aux['title'], $aux );
  225. $aux['thumbnail_url'] = liberty_fetch_thumbnails( array(
  226. 'storage_path' => $this->getGalleryThumbBaseUrl( $aux['content_id'] ),
  227. 'mime_image' => FALSE
  228. ));
  229. // deal with the parsing
  230. $parseHash['format_guid'] = $aux['format_guid'];
  231. $parseHash['content_id'] = $aux['content_id'];
  232. $parseHash['user_id'] = $aux['user_id'];
  233. $parseHash['data'] = $aux['data'];
  234. $aux['parsed_data'] = $this->parseData( $parseHash );
  235. // sucky additional query to fetch item number without subselect
  236. if( $gBitDbType == 'mysql' || $gBitDbType == 'mysqli' ) {
  237. $item_count_query = "SELECT COUNT( trm.`item_content_id` ) FROM `".BIT_DB_PREFIX."treasury_map` trm WHERE trm.`gallery_content_id`=?";
  238. $aux['item_count'] = $this->mDb->getOne( $item_count_query, array( $aux['content_id'] ));
  239. }
  240. if( !empty( $pListHash['get_sub_tree'] ) ) {
  241. $aux['subtree'] = $struct->getSubTree( $aux['structure_id'] );
  242. }
  243. $ret[$aux['content_id']] = $aux;
  244. }
  245. }
  246. $query = "SELECT COUNT( lc.`title` )
  247. FROM `".BIT_DB_PREFIX."treasury_gallery` trg
  248. INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( lc.`content_id` = trg.`content_id` )
  249. LEFT OUTER JOIN `".BIT_DB_PREFIX."users_users` uue ON ( uue.`user_id` = lc.`modifier_user_id` )
  250. LEFT OUTER JOIN `".BIT_DB_PREFIX."users_users` uuc ON ( uuc.`user_id` = lc.`user_id` )
  251. INNER JOIN `".BIT_DB_PREFIX."liberty_structures` ls ON ( ls.`structure_id` = trg.`structure_id` )
  252. $joinSql $whereSql";
  253. $pListHash['cant'] = $this->mDb->getOne( $query, $bindVars );
  254. LibertyContent::postGetList( $pListHash );
  255. return $ret;
  256. }
  257. /**
  258. * Store TreasuryGallery
  259. *
  260. * @param $pParamHash contains all data to store the gallery
  261. * @param $pParamHash[title] title of the new gallery
  262. * @param $pParamHash[edit] description of the gallery
  263. * @param $pParamHash[root_structure_id] if this is set, it will add the gallery to this structure. if it's not set, a new structure / top level gallery is created
  264. * @param $pParamHash[parent_id] set the structure_id that will server as the parent in the structure
  265. * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
  266. * @access public
  267. **/
  268. function store( &$pParamHash ) {
  269. $this->mDb->StartTrans();
  270. if( $this->verify( $pParamHash ) && LibertyContent::store( $pParamHash ) ) {
  271. $table = BIT_DB_PREFIX."treasury_gallery";
  272. // this really confusing, strange order way of saving items is due to strange behaviour of GenID
  273. // probably has to do with not null default nextval('public.liberty_structures_id_seq'::text)
  274. if( !empty( $pParamHash['update'] ) ) {
  275. if( !empty( $pParamHash['gallery_store'] ) ) {
  276. $result = $this->mDb->associateUpdate( $table, $pParamHash['gallery_store'], array( "content_id" => $this->mContentId ));
  277. }
  278. $pParamHash['structure_location_id'] = $this->mStructureId;
  279. } else {
  280. // update the gallery_store and structure_store content_id with the one from LibertyMime::store()
  281. $pParamHash['structure_store']['content_id'] = $pParamHash['content_id'];
  282. $pParamHash['gallery_store']['content_id'] = $pParamHash['content_id'];
  283. // we need to store the new structure node now
  284. global $gStructure;
  285. // create new object if needed
  286. if( empty( $gStructure ) ) {
  287. $gStructure = new LibertyStructure();
  288. }
  289. $pParamHash['structure_location_id'] = $gStructure->storeNode( $pParamHash['structure_store'] );
  290. // get the corrent structure_id
  291. // structure_id has to be done like this since it's screwed up in the schema
  292. $pParamHash['gallery_store']['structure_id'] = $this->mDb->getOne( "SELECT MAX( `structure_id` ) FROM `".BIT_DB_PREFIX."liberty_structures`" );
  293. $result = $this->mDb->associateInsert( $table, $pParamHash['gallery_store'] );
  294. }
  295. $this->mDb->CompleteTrans();
  296. // process image upload
  297. if( empty( $this->mErrors )) {
  298. // now deal with the uploaded image
  299. if( !empty( $pParamHash['thumb']['tmp_name'] )) {
  300. $checkFunc = liberty_get_function( 'can_thumbnail' );
  301. if( $checkFunc( $pParamHash['thumb']['type'] )) {
  302. $fileHash = $pParamHash['thumb'];
  303. $fileHash['dest_path'] = $this->getGalleryThumbBaseUrl();
  304. $fileHash['source_file'] = $fileHash['tmp_name'];
  305. liberty_clear_thumbnails( $fileHash );
  306. liberty_generate_thumbnails( $fileHash );
  307. } else {
  308. $this->mErrors['thumb'] = tra( "The file you uploaded doesn't appear to be a valid image. The reported mime type is" ).": ".$pParamHash['thumb']['type'];
  309. }
  310. }
  311. }
  312. $this->load();
  313. }
  314. return( count( $this->mErrors ) == 0 );
  315. }
  316. /**
  317. * Verify, clean up and prepare data to be stored
  318. *
  319. * @param $pParamHash all information that is being stored. will update $pParamHash by reference with fixed array of itmes
  320. * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
  321. * @access private
  322. **/
  323. function verify( &$pParamHash ) {
  324. // make sure we're all loaded up if everything is valid
  325. if( $this->isValid() && empty( $this->mInfo ) ) {
  326. $this->load();
  327. }
  328. // It is possible a derived class set this to something different
  329. if( empty( $pParamHash['content_type_guid'] ) ) {
  330. $pParamHash['content_type_guid'] = $this->mContentTypeGuid;
  331. }
  332. // make sure we know this is an update
  333. if( @BitBase::verifyId( $this->mContentId ) ) {
  334. $pParamHash['content_id'] = $this->mContentId;
  335. $pParamHash['update'] = TRUE;
  336. }
  337. // ---------- Gallery Store
  338. $pParamHash['gallery_store']['is_private'] = empty( $pParamHash['is_private'] ) ? 'n' : 'y';
  339. // ---------- Content store
  340. // check for name issues, truncate length if too long
  341. if( !empty( $pParamHash['title'] ) ) {
  342. if( !@BitBase::verifyId( $this->mContentId ) ) {
  343. $pParamHash['content_store']['title'] = substr( $pParamHash['title'], 0, BIT_CONTENT_MAX_TITLE_LEN );
  344. } else {
  345. $pParamHash['content_store']['title'] = ( isset( $pParamHash['title'] ) ) ? substr( $pParamHash['title'], 0, BIT_CONTENT_MAX_TITLE_LEN ) : $this->mInfo['title'];
  346. }
  347. } else {
  348. $this->mErrors['title'] = 'You must enter a name for this gallery.';
  349. }
  350. // sort out the description
  351. if( $this->isValid() && !empty( $this->mInfo['data'] ) && empty( $pParamHash['edit'] ) ) {
  352. $pParamHash['content_store']['data'] = '';
  353. } elseif( empty( $pParamHash['edit'] ) ) {
  354. unset( $pParamHash['edit'] );
  355. } else {
  356. $pParamHash['content_store']['data'] = substr( $pParamHash['edit'], 0, 250 );
  357. }
  358. // Individual gallery preference store - dealt with by LibertyContent::store();
  359. if( empty( $pParamHash['preferences']['allow_comments'] )) {
  360. $pParamHash['preferences']['allow_comments'] = NULL;
  361. }
  362. $pParamHash['preferences_store'] = !empty( $pParamHash['preferences'] ) ? $pParamHash['preferences'] : NULL;
  363. // structure store
  364. if( @BitBase::verifyId( $pParamHash['root_structure_id'] ) ) {
  365. $pParamHash['structure_store']['root_structure_id'] = $pParamHash['root_structure_id'];
  366. } else {
  367. $pParamHash['structure_store']['root_structure_id'] = NULL;
  368. }
  369. if( @BitBase::verifyId( $pParamHash['parent_id'] ) ) {
  370. $pParamHash['structure_store']['parent_id'] = $pParamHash['parent_id'];
  371. } else {
  372. $pParamHash['structure_store']['parent_id'] = NULL;
  373. }
  374. return( count( $this->mErrors ) == 0 );
  375. }
  376. /**
  377. * expunge a gallery
  378. *
  379. * @param array $pParamHash
  380. * @access public
  381. * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  382. */
  383. function expunge( $pForceDeleteItems = FALSE ) {
  384. $ret = FALSE;
  385. if( $this->isValid() ) {
  386. $this->mDb->StartTrans();
  387. // get all items that are part of the sub tree
  388. require_once( LIBERTYSTRUCTURE_PKG_PATH.'LibertyStructure.php' );
  389. $struct = new LibertyStructure();
  390. $tree = $struct->getSubTree( $this->mStructureId );
  391. // include the current id as well - needed when there are no sub-galleries
  392. $galleryContentIds[] = $this->mContentId;
  393. foreach( $tree as $node ) {
  394. $galleryContentIds[] = $node['content_id'];
  395. }
  396. $galleryContentIds = array_unique( $galleryContentIds );
  397. // Create Item Object
  398. require_once( TREASURY_PKG_PATH.'TreasuryItem.php');
  399. $itemObject = new TreasuryItem();
  400. // Go through all galleries we want to remove
  401. foreach( $galleryContentIds as $gid ) {
  402. // make sure the gallery is fully loaded
  403. $this->mContentId = $gid;
  404. $this->load();
  405. $itemContentIds = $this->mDb->getCol( "SELECT `item_content_id` FROM `".BIT_DB_PREFIX."treasury_map` WHERE `gallery_content_id`=?", array( $gid ) );
  406. $itemContentIds = array_unique( $itemContentIds );
  407. // Delete items in galleries
  408. foreach( $itemContentIds as $iid ) {
  409. if( $pForceDeleteItems ) {
  410. // Remove item even if it exists in other galleries
  411. $count = 1;
  412. } else {
  413. // Only delete item if it doesn't exist in other galleries
  414. $count = $this->mDb->getOne( "SELECT COUNT( `item_content_id` ) FROM `".BIT_DB_PREFIX."treasury_map` WHERE `item_content_id`=?", array( $iid ) );
  415. }
  416. // Only delete item if it doesn't exist in other galleries
  417. if( $count == 1 ) {
  418. $itemObject->mContentId = $iid;
  419. $itemObject->load();
  420. if( !$itemObject->expunge() ) {
  421. $this->mErrors['expunge'][] = $itemObject->mErrors;
  422. }
  423. }
  424. }
  425. // Next, we remove any icons if they exist
  426. if( $thumbdir = $this->getGalleryThumbBaseUrl() ) {
  427. @unlink_r( BIT_ROOT_PATH.$thumbdir );
  428. }
  429. // Now that all the items are gone, we can start nuking gallery entries
  430. // remove gallery preferences
  431. $query = "DELETE FROM `".BIT_DB_PREFIX."liberty_content_prefs` WHERE `content_id`=?";
  432. $result = $this->mDb->query( $query, array( $this->mContentId ) );
  433. // Remove map entries
  434. $sql = "DELETE FROM `".BIT_DB_PREFIX."treasury_map` WHERE `gallery_content_id`=?";
  435. $rs = $this->mDb->query( $sql, array( $gid ) );
  436. // Remove gallery entry
  437. $sql = "DELETE FROM `".BIT_DB_PREFIX."treasury_gallery` WHERE `content_id`=?";
  438. $rs = $this->mDb->query( $sql, array( $gid ) );
  439. // Let liberty remove all the content entries for this gallery
  440. if( !LibertyContent::expunge() ) {
  441. $errors = TRUE;
  442. }
  443. // Finally nuke the structure in liberty_structures
  444. $struct->removeStructureNode( $this->mStructureId, FALSE );
  445. }
  446. if( empty( $errors ) ) {
  447. $this->mDb->CompleteTrans();
  448. $ret = TRUE;
  449. } else {
  450. $this->mDb->RollbackTrans();
  451. $ret = FALSE;
  452. }
  453. }
  454. return $ret;
  455. }
  456. /**
  457. * Returns HTML link to display a gallery or item
  458. *
  459. * @param $pTitle is the gallery we want to see
  460. * @param $pContentId content id of the gallery in question
  461. * @return the link to display the page.
  462. **/
  463. function getDisplayLink( $pTitle=NULL, $pMixed=NULL ) {
  464. global $gBitSystem;
  465. if( empty( $pTitle ) && !empty( $this ) ) {
  466. $pTitle = $this->getTitle();
  467. }
  468. if( empty( $pMixed ) && !empty( $this ) ) {
  469. $pMixed = $this->mInfo;
  470. }
  471. $ret = $pTitle;
  472. if( !empty( $pTitle ) && !empty( $pMixed ) ) {
  473. if( $gBitSystem->isPackageActive( 'treasury' ) ) {
  474. $ret = '<a title="'.htmlspecialchars( $pTitle ).'" href="'.TreasuryGallery::getDisplayUrl( $pMixed['content_id'] ).'">'.htmlspecialchars( $pTitle ).'</a>';
  475. }
  476. }
  477. return $ret;
  478. }
  479. /**
  480. * Generates the URL to this gallery
  481. * @param $pContentId is the gallery we want to see
  482. * @return the link to display the page.
  483. **/
  484. function getDisplayUrl( $pContentId=NULL, $pMixed=NULL ) {
  485. global $gBitSystem;
  486. $ret = NULL;
  487. // try to get the correct content_id from anywhere possible
  488. if( !@BitBase::verifyId( $pContentId ) && $this->isValid() ) {
  489. $pContentId = $this->mContentId;
  490. } elseif( !@BitBase::verifyId( $pContentId ) && !empty( $pMixed['content_id'] ) ) {
  491. $pContentId = $pMixed['content_id'];
  492. }
  493. if( @BitBase::verifyId( $pContentId ) ) {
  494. if( $gBitSystem->isFeatureActive( 'pretty_urls' ) || $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ) {
  495. $ret = TREASURY_PKG_URL.'gallery/'.$pContentId;
  496. } else {
  497. $ret = TREASURY_PKG_URL.'view.php?content_id='.$pContentId;
  498. }
  499. }
  500. return $ret;
  501. }
  502. /**
  503. * Get the base path to where the gallery thumbnail is stored - create directory if needed
  504. *
  505. * @param numeric $pContentId Content ID of gallery in question
  506. * @access public
  507. * @return Path to thumbnail directory on success, FALSE on failure
  508. */
  509. function getGalleryThumbBaseUrl( $pContentId = NULL ) {
  510. $ret = FALSE;
  511. if( !@BitBase::verifyId( $pContentId ) && $this->isValid() ) {
  512. $pContentId = $this->mContentId;
  513. }
  514. if( @BitBase::verifyId( $pContentId ) ) {
  515. // getStorageBranch is a private function, so this is a no-no but necessary until LA offers something better
  516. $ret = LibertyMime::getStorageBranch( 'gallery_thumbnails/'.$pContentId, NULL, TREASURY_PKG_NAME );
  517. }
  518. return $ret;
  519. }
  520. /**
  521. * Returns the create/edit url to a gallery
  522. * @param number $pContentId a valid content id
  523. * @param array $pMixed a hash of params to add to the url
  524. */
  525. function getEditUrl( $pContentId = NULL, $pMixed = NULL ){
  526. if( @BitBase::verifyId( $pContentId ) ) {
  527. $ret = TREASURY_PKG_URL.'edit_gallery.php?content_id='.$pContentId;
  528. } elseif( $this->isValid() ) {
  529. $ret = TREASURY_PKG_URL.'edit_gallery.php?content_id='.$this->mContentId;
  530. } else {
  531. $ret = TREASURY_PKG_URL.'edit_gallery.php'.(!empty( $pMixed )?"?":"");
  532. }
  533. foreach( $pMixed as $key => $value ){
  534. if( $key != "content_id" || ( $key == "content_id" && @BitBase::verifyId( $value ) ) ) {
  535. $ret .= (isset($amp)?"&":"").$key."=".$value;
  536. }
  537. $amp = TRUE;
  538. }
  539. return $ret;
  540. }
  541. }
  542. ?>