summaryrefslogtreecommitdiff
path: root/display_bitblog_inc.php
blob: d2ce8424915c5d044aa87950ee57efe9be7549ac (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
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
<?php
/**
 * @package blogs
 * @subpackage functions
 * 
 * Copyright (c) 2004-2006, bitweaver.org
 * All Rights Reserved. See copyright.txt for details and a complete list of authors.
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
 */

/**
 * required setup
 */
require_once( BLOGS_PKG_PATH.'BitBlog.php' );

$displayHash = array( 'perm_name' => 'p_blogs_view' );
$gBlog->invokeServices( 'content_display_function', $displayHash );

$gBitSystem->verifyPackage( 'blogs' );

if( isset($_REQUEST['user_id']) && !isset( $_REQUEST['blog_id'] ) ) {
	// We will try and grab the first blog owned by the user id given
	$blogsList = $gBlog->list_user_blogs($_REQUEST['user_id']);
	if (!empty($blogsList[0]['blog_id'])) {
		$_REQUEST['blog_id'] = $blogsList[0]['blog_id'];
	}
}

if (!isset($_REQUEST["blog_id"])) {
	$gBitSystem->fatalError( 'No blog indicated' );
}

$gBitSmarty->assign('individual', 'n');

if ($gBitUser->object_has_one_permission( $_REQUEST["blog_id"], $gBlog->getContentType() )) {
	$gBitSmarty->assign('individual', 'y');

	if (!$gBitUser->isAdmin()) {
		// Now get all the permissions that are set for this type of permissions 'image gallery'
		//$perms = $gBitUser->getPermissions('', BLOGS_PKG_NAME );
		$perms = $gBitSystem->getPermissionInfo(NULL, BLOGS_PKG_NAME);

		foreach ($perms as $perm_name => $permInfo) {
			//$perm_name = $perm["perm_name"];

			if ($gBitUser->object_has_permission( $gBitUser->mUserId, $_REQUEST["blog_id"], $gBlog->getContentType(), $perm_name ) ) {
				$$perm_name = 'y';

				$gBitSmarty->assign("$perm_name", 'y');
			} else {
				$$perm_name = 'n';

				$gBitSmarty->assign("$perm_name", 'n');
			}
		}
	}
}

$gBitSystem->verifyPermission( 'p_blogs_view' );

if( $gBlog->getField( 'blog_style' ) && $gBitSystem->getConfig('users_themes') == 'h' ) {
	$gBitSystem->setStyle( $gBlog->getField( 'blog_style' ) );
	$gBitSystem->mStyles['styleSheet'] = $gBitSystem->getStyleCss( $gBlog->getField( 'blog_style' ), $gBlog->getField( 'user_id' ) );
	$gBitSmarty->assign( 'userStyle', $gBlog->getField( 'blog_style' ) );
}

if( !$gBlog->hasEditPermission() ) {
	$gBlog->addHit();
}



if (isset($_REQUEST["remove"])) {
	$blogPost = new BitBlogPost( $_REQUEST["remove"] );
	if( $blogPost->load() ) {
		if( !$blogPost->hasEditPermission() ) {
			$gBitSystem->verifyPermission( 'p_blogs_admin', "Permission denied you cannot remove this post" );
		}

		if( !empty( $_REQUEST['cancel'] ) ) {
			// user cancelled - just continue on, doing nothing
		} elseif( empty( $_REQUEST['confirm'] ) ) {
			$formHash['remove'] = $_REQUEST['remove'];
			$formHash['blog_id'] = $_REQUEST['blog_id'];
			$gBitSystem->confirmDialog( $formHash, array( 'warning' => 'Are you sure you want to remove post '.$_REQUEST['remove'].'?' ) );
		} else {
			$blogPost->expunge();
			bit_redirect( BLOGS_PKG_URL );
		}
	}
}


$now = $gBitSystem->getUTCTime();

$blogPost = new BitBlogPost();
$listHash = array();
$listHash['blog_id'] = $_REQUEST['blog_id'];
$listHash['parse_data'] = TRUE;
$listHash['max_records'] = $gBlog->getField( 'max_posts' );
$listHash['load_num_comments'] = TRUE;
$blogPosts = $blogPost->getList( $listHash );
if( count( $blogPosts['data'] ) ) {
	// If there're more records then assign next_offset
	$gBitSmarty->assign_by_ref('blogPosts', $blogPosts["data"]);
} elseif( $gBlog->hasPostPermission() ) {
	bit_redirect( BLOGS_PKG_URL.'post.php?blog_id='.$gBlog->getField( 'blog_id' ) );
}

if( $gBitSystem->isFeatureActive( 'users_watches' ) ) {
	if( $gBitUser->isValid() && isset( $_REQUEST['watch_event'] ) ) {
		if ($_REQUEST['watch_action'] == 'add') {
			$blogPost = new BitBlogPost( $_REQUEST['watch_object'] );
			if( $blogPost->load() ) {
				$gBitUser->storeWatch( $_REQUEST['watch_event'], $_REQUEST['watch_object'], tra('blog'), $blogPost->mInfo['title'], $blogPost->getDisplayUrl() );
			}
		} else {
			$gBitUser->expungeWatch( $_REQUEST['watch_event'], $_REQUEST['watch_object'] );
		}
	}

	$gBitSmarty->assign('user_watching_blog', 'n');

	if ( $watch = $gBitUser->getEventWatches( $gBitUser->mUserId, 'blog_post', $_REQUEST['blog_id'])) {
		$gBitSmarty->assign('user_watching_blog', 'y');
	}
}

// Display the template
$gBitSystem->display( 'bitpackage:blogs/view_blog.tpl', $gBlog->getTitle() );

?>