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
|
<?php
/**
* Elgg Lorea Favorites Plugin
*/
elgg_register_event_handler('init','system','favorites_init');
function favorites_init(){
elgg_register_page_handler('favorites','favorites_page_handler');
elgg_extend_view("js/elgg", "js/favorites");
elgg_extend_view("page/elements/sidebar", "favorites/sidebar");
if ( elgg_is_logged_in() ) {
elgg_register_menu_item(
'site',
array(
'name' => 'favorites',
'text' => elgg_echo('favorites:menu'),
'href' => "favorites/view/"
)
);
}
$plugin_path = elgg_get_plugins_path();
elgg_register_action(
"favorites/add",
$plugin_path . "favorites/actions/favorites/add.php"
);
elgg_register_action(
"favorites/remove",
$plugin_path . "favorites/actions/favorites/remove.php"
);
elgg_register_plugin_hook_handler(
'register',
'menu:entity',
'favorites_entity_menu_setup'
);
elgg_register_widget_type(
'favorites',
elgg_echo('favorites:widget:title'),
elgg_echo('favorites:widget:description')
);
}
function favorites_page_handler($page) {
echo elgg_view_page(
elgg_echo("favorites:items"),
elgg_view_layout(
'one_sidebar',
array(
'title' => elgg_echo("favorites:items"),
'content' => elgg_view('favorites/view'),
'sidebar' => elgg_view('favorites/sidebar'),
)
)
);
return true;
}
function favorites_entity_menu_setup($hook, $type, $return, $params) {
if (elgg_in_context('widgets')) {
return $return;
}
if ( elgg_is_logged_in() ) {
$entity = $params['entity'];
if ($entity instanceof ElggEntity) {
$options = array(
'name' => 'favorite',
'text' => elgg_view('favorites/button', array('entity' => $entity)),
'is_action' => true,
'is_trusted' => true
);
$return[] = ElggMenuItem::factory($options);
}
}
return $return;
}
|