summaryrefslogtreecommitdiff
path: root/bookmark.php
blob: cc78ed39afe426169da444941ed26452d2d9bf5c (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
<?php
/**
 * A universal helper to bookmark any content object for a user
 * Currently only accessible through ajax/json
 * Those wishing for a non-js implementation feel free to modify
 *
 * @package users
 */

/**
 * required setup
 */
require_once '../kernel/includes/setup_inc.php';
use Bitweaver\KernelTools;

$statusCode = 205;
$error = true;
$msg = "";

if( $gBitUser->isRegistered() ){
	if( !empty( $_REQUEST['content_id'] ) && $gContent = LibertyBase::getLibertyObject( $_REQUEST['content_id'] ) ) {
		// verify user has access to view this content
		$gContent->load();
		if( $gContent->hasViewPermission() ){
			if( $gContent->hasService( CONTENT_SERVICE_USERS_FAVS ) ){
				// default action is to add the favorite
				$_REQUEST['action'] = empty( $_REQUEST['action'] )?'add':$_REQUEST['action']; 
				// add or remove 
				switch( $_REQUEST['action'] ){
					case 'add':
						$gBitUser->storeFavorite( $_REQUEST['content_id'] );
						$bookmarkState = 1;
						$msg = KernelTools::tra( 'This content has been added to your favorites' );
						break;
					case 'remove':
						$gBitUser->expungeFavorite( $_REQUEST['content_id'] );
						$bookmarkState = 0;
						$msg = KernelTools::tra( 'This content has been removed from your favorites' );
						break;
				}
				$gBitSmarty->assign( 'bookmarkState', $bookmarkState );
				$gBitSmarty->assign( 'contentId', $_REQUEST['content_id'] );
				$error = false;
			}else{
				$statusCode = 401;
				$msg = KernelTools::tra( 'You can not bookmark this type of content, bookmarking denied' );
			}
		}else{
			$statusCode = 401;
			$msg = KernelTools::tra( 'You do not have permission to view this content, bookmarking denied' );
		}
	}else{
		$statusCode = 400;
		$msg = KernelTools::tra( 'No content was specified to bookmark' );
	}
}else{
	$msg = KernelTools::tra( 'You must be a registered user to bookmark content' );
}

$gBitSmarty->assign( 'statusCode', $statusCode );
$gBitSmarty->assign( 'error', $error );
$gBitSmarty->assign( 'msg', $msg );
$gBitThemes->setFormatHeader( 'json' );
$gBitSystem->display('bitpackage:users/edit_user_fav_json.tpl', null, array( 'format' => 'center_only', 'display_mode' => 'edit' ));