forked from lianglee/Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathossn_com.php
More file actions
176 lines (172 loc) · 4.87 KB
/
ossn_com.php
File metadata and controls
176 lines (172 loc) · 4.87 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/**
* Open Source Social Network
*
* @package Open Source Social Network
* @author Open Social Website Core Team <info@informatikon.com>
* @copyright 2014 iNFORMATIKON TECHNOLOGIES
* @license General Public Licence http://www.opensource-socialnetwork.org/licence
* @link http://www.opensource-socialnetwork.org/licence
*/
define('BLOG', ossn_route()->com . 'Blog/');
require_once(BLOG . 'classes/Blog.php');
/**
* Blog Init
*
* @return void
*/
function blog_init() {
if(ossn_isLoggedin()) {
ossn_register_action('blog/add', BLOG . 'actions/add.php');
ossn_register_action('blog/edit', BLOG . 'actions/edit.php');
ossn_register_action('blog/delete', BLOG . 'actions/delete.php');
}
ossn_register_callback('user', 'delete', 'ossn_user_blog_delete');
ossn_register_callback('page', 'load:profile', 'ossn_profile_blog_menu');
ossn_extend_view('css/ossn.default', 'css/blog');
ossn_extend_view('js/opensource.socialnetwork', 'js/blog');
ossn_register_page('blog', 'ossn_blog_page_handler');
ossn_register_sections_menu('newsfeed', array(
'name' => 'allblogs',
'text' => ossn_print('blog:all'),
'url' => ossn_site_url('blog/all'),
'section' => 'blog',
'icon' => true
));
ossn_register_sections_menu('newsfeed', array(
'name' => 'addblog',
'text' => ossn_print('blog:add'),
'url' => ossn_site_url('blog/add'),
'section' => 'blog',
'icon' => true,
));
}
/**
* Get blog object
*
* @param integer $guid A blog guid
*
* @return object|boolean
*/
function ossn_get_blog($guid) {
if($object = ossn_get_object($guid)) {
$type = (array) $object;
if($object->subtype == 'blog') {
return arrayObject($type, 'Blog');
}
}
return false;
}
/**
* Blog pages
*
* @param array $pages A pages
*
* @return mixdata
*/
function ossn_blog_page_handler($pages) {
$page = $pages[0];
switch($page) {
case 'add':
if(!ossn_isLoggedin()){
ossn_error_page();
}
$title = ossn_print('blog:add');
$contents['content'] = ossn_plugin_view('blog/pages/add');
$content = ossn_set_page_layout('newsfeed', $contents);
echo ossn_view_page($title, $content);
break;
case 'view':
$blog = ossn_get_blog($pages[1]);
if(!$blog) {
ossn_error_page();
}
$title = $blog->title;
$contents['content'] = ossn_plugin_view('blog/pages/view', array(
'blog' => $blog
));
$content = ossn_set_page_layout('newsfeed', $contents);
echo ossn_view_page($title, $content);
break;
case 'edit':
if(!ossn_isLoggedin()){
ossn_error_page();
}
$blog = ossn_get_blog($pages[1]);
if(!$blog) {
ossn_error_page();
}
if(($blog->owner_guid == ossn_loggedin_user()->guid) || ossn_loggedin_user()->canModerate()) {
$title = ossn_print('blog:edit');
$contents['content'] = ossn_plugin_view('blog/pages/edit', array(
'blog' => $blog
));
$content = ossn_set_page_layout('newsfeed', $contents);
echo ossn_view_page($title, $content);
} else {
ossn_error_page();
}
break;
case 'all':
$blog = new Blog;
if(!isset($pages[1])) {
$blogs = $blog->getBlogs();
$count = $blog->getBlogs(array(
'count' => true
));
} else {
$user = ossn_user_by_guid($pages[1]);
$blogs = $blog->getUserBlogs($user);
$count = $blog->getUserBlogs($user, array(
'count' => true
));
}
$title = ossn_print('blog:all');
$contents['content'] = ossn_plugin_view('blog/pages/all', array(
'blogs' => $blogs,
'count' => $count
));
$content = ossn_set_page_layout('newsfeed', $contents);
echo ossn_view_page($title, $content);
break;
}
}
/**
* Delete user events
*
* @param string $callback A name of callback
* @param string $type A event type
* @param array $params A option values
*
* @return void
*/
function ossn_user_blog_delete($callback, $type, $params) {
if(!empty($params['entity']->guid)) {
$blogs = new Blog;
$list = $blogs->getUserBlogs($params['entity']->guid, array(
'page_limit' => false
));
foreach($list as $item) {
$item->deleteObject();
}
}
}
/**
* Event profile menu
*
* @param string $event A name of callback
* @param string $type A event type
* @param array $params A option values
*
* @return void
*/
function ossn_profile_blog_menu($event, $type, $params) {
$guid = ossn_get_page_owner_guid();
$url = ossn_site_url();
ossn_register_menu_item('user_timeline', array(
'name' => 'blog',
'href' => ossn_site_url("blog/all/{$guid}"),
'text' => ossn_print('blogs')
));
}
ossn_register_callback('ossn', 'init', 'blog_init');