summaryrefslogtreecommitdiff
path: root/includes/get_content_list_inc.php
blob: b921b09668ce79d3bc969ff4d071b67ba806696a (plain)
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
<?php
/**
 * get_content_list
 *
 * @author   Christian Fowler>
 * @version  $Revision$
 * @package  liberty
 * @subpackage functions
 */

/**
 * required setup
 */
use Bitweaver\BitBase;
use Bitweaver\KernelTools;
use Bitweaver\Liberty\LibertyContent;
global $gLibertySystem;

if( empty( $gContent ) || !is_object( $gContent ) ) {
	$gContent = new LibertyContent();
}

$contentTypeGuids = [];
if( !empty( $_REQUEST['content_type_guid'] )) {
	$guids = ( !is_array( $_REQUEST['content_type_guid'] ) ) ? explode( ",", $_REQUEST['content_type_guid'] ) : $_REQUEST['content_type_guid'];
	/**
	 * if an empty string was passed in an array (likely since it is used for ALL) then the user has requested all so return all
	 * even if they have requested additional content types too - ALL is ALL
	 * this check is reversed in that if no empty string in the array then we pass the array of content types to be limited on
	 **/
	if( !in_array( "", $guids ) ){
		$contentTypeGuids = $guids;
	}
}

// get_content_list_inc doesn't use $_REQUEST parameters as it might not be the only list in the page that needs sorting and limiting
if( empty( $contentListHash ) ) {
	$contentListHash = [
		'content_type_guid' => $contentSelect = empty( $_REQUEST['content_type_guid'] ) ? null : $contentTypeGuids,
		// pagination offset
		'offset'            => !empty( $offset_content ) ? $offset_content : null,
		// maximum number of records displayed on a page
		'max_records'       => !empty( $max_content ) ? $max_content : ( !empty( $_REQUEST['max_records'] ) ? $_REQUEST['max_records'] : 100 ),
		// sort by this: <table column>_asc (or _desc)
		'sort_mode'         => !empty( $content_sort_mode ) ? $content_sort_mode : 'title_asc',
		// limit the result to this set
		'find'              => !empty( $_REQUEST["find"] ) ? $_REQUEST["find"] : null,
		// display this page number - replaces antiquated offset
		'page'              => !empty( $_REQUEST["list_page"] ) ? $_REQUEST["list_page"] : (!empty( $_REQUEST["page"] ) ? $_REQUEST["page"] : 1),
		// only display content by this user
		'user_id'           => BitBase::verifyId( $_REQUEST['user_id'] ?? 0 ) ? $_REQUEST['user_id'] : null,
		// only display content modified more recently than this (UTC timestamp)
		'from_date'         => !empty( $_REQUEST["from_date"] ) ? $_REQUEST["from_date"] : null,
		// only display content modified before this (UTC timestamp)
		'until_date'        => !empty( $_REQUEST["until_date"] ) ? $_REQUEST["until_date"] : null,
		// get a thumbnail - off by default because it is expensive
		'thumbnail_size'    => !empty( $_REQUEST["thumbnail_size"] ) ? $_REQUEST["thumbnail_size"] : null,
	];

	if( !empty( $_REQUEST['output'] ) && ( $_REQUEST['output'] == 'json' || $_REQUEST['output'] == 'ajax' ) ) {
		foreach( $_REQUEST as $key => $value ) {
			if ( !is_array($value) ){
				if( strstr( $value, ',' ) ) {
					$_REQUEST[$key] = explode( ",", $value );
				}
			}
		}
	}

	$contentListHash = array_merge( $_REQUEST, $contentListHash );
}

// Finally we're ready to get some content
$contentList = $gContent->getContentList( $contentListHash );

if( empty( $contentTypes ) ) {
	$contentTypes = [ '' => KernelTools::tra( 'All Content' ) ];
	foreach( $gLibertySystem->mContentTypes as $cType ) {
		$contentTypes[$cType['content_type_guid']] = $gLibertySystem->getContentTypeName( $cType['content_type_guid'], true );
	}
	asort( $contentTypes );
}
global $gBitSystem, $gBitUser;
if( $gBitSystem->isFeatureActive( 'liberty_display_status' ) &&  $gBitUser->hasPermission( 'p_liberty_view_all_status' )) {
	$contentStatuses = $gContent->getAvailableContentStatuses();
	$contentStatuses[''] = 'All Statuses';
	$contentStatuses['not_available'] = 'All but Available';
	$gBitSmarty->assign( 'content_statuses', $contentStatuses );
}