-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.php
More file actions
130 lines (110 loc) · 3.83 KB
/
start.php
File metadata and controls
130 lines (110 loc) · 3.83 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
<?php
/*
* Instagram Feed
*
* @author Per Jensen
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
* @copyright Copyright (c) 2019, Per Jensen
*
*/
return function() {
elgg_register_event_handler('init', 'system', 'instagram_feed_init');
};
function instagram_feed_init() {
elgg_set_entity_class('object', 'instagram_feed', ElggInstagramFeed::class);
// plugin specific CSS
elgg_extend_view('elgg.css', 'instagram_feed/instagram_feed.css');
// add instagram link to owner block
elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'instagram_feed_owner_block_menu');
// Register for notifications
elgg_register_notification_event('object', 'instagram_feed', ['create']);
elgg_register_plugin_hook_handler('prepare', 'notification:create:object:instagram_feed', 'instagram_feed_prepare_notification');
// allow to be liked
elgg_register_plugin_hook_handler('likes:is_likable', 'object:instagram_feed', 'Elgg\Values::getTrue');
// menus
elgg_register_menu_item('site', [
'name' => 'instagram',
'icon' => 'instagram',
'text' => elgg_echo('collection:object:instagram_feed'),
'href' => elgg_generate_url('default:object:instagram_feed'),
]);
}
/**
* Prepare the add/edit form variables
*
* @param ElggObject $instagram_feed A instagram_feed object.
* @return array
*/
function instagram_feed_prepare_form_vars($instagram_feed = null) {
// input names => defaults
$values = [
'title' => get_input('title', ''),
'instagram_access_token' => get_input('instagram_access_token', ''),
'description' => '',
'access_id' => ACCESS_DEFAULT,
'tags' => '',
'container_guid' => elgg_get_page_owner_guid(),
'guid' => null,
'entity' => $instagram_feed,
];
if ($instagram_feed) {
foreach (array_keys($values) as $field) {
if (isset($instagram_feed->$field)) {
$values[$field] = $instagram_feed->$field;
}
}
}
if (elgg_is_sticky_form('instagram_feed')) {
$sticky_values = elgg_get_sticky_values('instagram_feed');
foreach ($sticky_values as $key => $value) {
$values[$key] = $value;
}
}
elgg_clear_sticky_form('instagram_feed');
return $values;
}
/**
* Prepare a notification message about a new feed
*
* @param string $hook Hook name
* @param string $type Hook type
* @param Elgg\Notifications\Notification $notification The notification to prepare
* @param array $params Hook parameters
* @return Elgg\Notifications\Notification
*/
function instagram_feed_prepare_notification($hook, $type, $notification, $params) {
$entity = $params['event']->getObject();
$owner = $params['event']->getActor();
$language = $params['language'];
$descr = $entity->description;
$title = $entity->getDisplayName();
$notification->subject = elgg_echo('instagram_feed:notify:subject', [$title], $language);
$notification->body = elgg_echo('instagram_feed:notify:body', [
$owner->getDisplayName(),
$title,
$descr,
$entity->getURL()
], $language);
$notification->summary = elgg_echo('instagram_feed:notify:summary', [$title], $language);
$notification->url = $entity->getURL();
return $notification;
}
/**
* Add a menu item to the user ownerblock
*
* @param string $hook 'register'
* @param string $type 'menu:owner_block'
* @param ElggMenuItem[] $return current return value
* @param array $params supplied params
*
* @return ElggMenuItem[]
*/
function instagram_feed_owner_block_menu($hook, $type, $return, $params) {
$entity = elgg_extract('entity', $params);
if ($entity instanceof ElggUser) {
$url = elgg_generate_url('collection:object:instagram_feed:owner', ['username' => $entity->username]);
$item = new ElggMenuItem('instagram_feed', elgg_echo('collection:object:instagram_feed'), $url);
$return[] = $item;
}
return $return;
}