diff options
| author | wjames5 <will@tekimaki.com> | 2010-03-13 20:09:01 +0000 |
|---|---|---|
| committer | wjames5 <will@tekimaki.com> | 2010-03-13 20:09:01 +0000 |
| commit | 3b7fe2f63338f4a616f17de84c7859e538fd55c8 (patch) | |
| tree | 1d6b5b6b2f778e925a8a85339d69667b4e3f2c24 /bookmark.php | |
| parent | b6a40cbcbc284db5afac88f76f773b99b5c24a00 (diff) | |
| download | users-3b7fe2f63338f4a616f17de84c7859e538fd55c8.tar.gz users-3b7fe2f63338f4a616f17de84c7859e538fd55c8.tar.bz2 users-3b7fe2f63338f4a616f17de84c7859e538fd55c8.zip | |
add user fav ajax service for easy bookmarking any content
Diffstat (limited to 'bookmark.php')
| -rw-r--r-- | bookmark.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/bookmark.php b/bookmark.php new file mode 100644 index 0000000..ec6fa33 --- /dev/null +++ b/bookmark.php @@ -0,0 +1,57 @@ +<?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 + */ + +/** + * required setup + */ +require_once( '../kernel/setup_inc.php' ); + +$statusCode = 205; +$error = TRUE; +$msg = ""; + +if( $gBitUser->isRegistered() ){ + if( !empty( $_REQUEST['content_id'] ) ){ + // verify user has access to view this content + $Content = LibertyBase::getLibertyObject( $_REQUEST['content_id'] ); + $Content->load(); + if( $Content->hasViewPermission() && $Content->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 = tra( 'This content has been added to your favorites' ); + break; + case 'remove': + $gBitUser->expungeFavorite( $_REQUEST['content_id'] ); + $bookmarkState = 0; + $msg = 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 = tra( 'You do not have permission to view this content, bookmarking denied' ); + } + }else{ + $statusCode = 400; + $msg = tra( 'No content was specified to bookmark' ); + } +}else{ + $msg = 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' )); |
