/
csb_blogUser.class.php
92 lines (74 loc) · 2.61 KB
/
csb_blogUser.class.php
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
<?php
/*
* This is for displaying blogs for which a user has access. The name is a bit
* of a misnomer, but I couldn't really think of a better name at the time.
*/
class csb_blogUser extends csb_blogAbstract {
/** An array of blog{} objects. */
protected $blogObjList;
/** An array with sub-arrays listing by blog_id, name, etc. */
protected $blogIndex;
//-------------------------------------------------------------------------
function __construct(cs_phpDB $db, $user, $location=null) {
if(strlen($user) > 2) {
parent::__construct($db);
$criteria = array(
'isActive'=>"t"
);
if(is_string($location) && strlen($location)) {
$criteria['location'] = $location;
}
$uid = $this->get_uid($user);
if(is_numeric($uid)) {
$this->validBlogs = $this->get_blogs($criteria, 'last_post_timestamp DESC');
$permObj = new csb_permission($db);
foreach($this->validBlogs as $blogId=>$data) {
$obj = new csb_blog($this->db, $data['blog_name']);
$canAccess = $permObj->can_access_blog($blogId, $uid);
if(!$canAccess) {
unset($this->validBlogs[$blogId]);
}
}
}
else {
throw new exception(__METHOD__ .": unable to retrieve uid for (". $user .")");
}
}
else {
throw new exception(__METHOD__ .": no username set (". $user .")");
}
}//end __construct()
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
public function get_most_recent_blogs($numPerBlog=1) {
if(is_array($this->validBlogs) && count($this->validBlogs)) {
$retval = array();
$this->blogs = array();
foreach($this->validBlogs as $blogId=>$blogData) {
$blogName = $blogData['blog_name'];
$this->blogs[$blogName] = new csb_blog($this->db, $blogName);
if(!$this->blogs[$blogName]->is_initialized()) {
$this->blogs[$blogName]->initialize_locals($blogName);
}
$recentBlogs = array();
try {
$recentBlogs = $this->blogs[$blogName]->get_recent_blogs($numPerBlog, 0, true);
if($numPerBlog == 1) {
$keys = array_keys($retval[$blogName]);
$recentBlogs = $retval[$blogName][$keys[0]];
}
}
catch(exception $e) {
$this->gfObj->debug_print(__METHOD__ .": no blogs for (". $blogName .")");
}
$retval[$blogName] = $recentBlogs;
}
}
else {
throw new exception(__METHOD__ .": no valid blogs to handle");
}
return($retval);
}//end get_most_recent_blogs()
//-------------------------------------------------------------------------
}
?>