forked from iionly/elggx_fivestar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activate.php
143 lines (122 loc) · 7.11 KB
/
activate.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
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
<?php
/**
* Activate Elggx Fivestar plugin
*
*/
// Upgrade settings
$oldversion = elgg_get_plugin_setting('version', 'elggx_fivestar');
$new_version = '2.3.1';
// Check if we need to run an upgrade
if (!$oldversion) {
$plugin = elgg_get_plugin_from_id('elggx_fivestar');
// Old versions of Elggx Fivestar used an array named view to save the Fivestar views which
// results in an issue with the plugin to be shown in the plugin list in the admin section.
// New name is elggx_fivestar_view and the old array needs to get deleted from the database.
$view = $plugin->view;
if (is_string($view)) {
$plugin->__unset('view');
$plugin->save();
}
}
// Set defaults if not yet set
if (!(int)elgg_get_plugin_setting('stars', 'elggx_fivestar')) {
elgg_set_plugin_setting('stars', '5', 'elggx_fivestar');
}
$change_vote = (int)elgg_get_plugin_setting('change_vote', 'elggx_fivestar');
if ($change_vote == 0) {
elgg_set_plugin_setting('change_cancel', 0, 'elggx_fivestar');
} else {
elgg_set_plugin_setting('change_cancel', 1, 'elggx_fivestar');
}
$values = elgg_get_plugin_setting('elggx_fivestar_view', 'elggx_fivestar');
if ($values) {
$elggx_fivestar_view = '';
$values = explode("\n", $values);
$values = array_filter($values);
$values = array_slice( $values, 0);
if (is_array($values)) {
$elggx_fivestar_view = implode("\n", $values);
}
elgg_set_plugin_setting('elggx_fivestar_view', $elggx_fivestar_view, 'elggx_fivestar');
} else {
elggx_fivestar_defaults();
}
// On Elgg 2.0 we have the object/discussion view instead of the object/groupforumtopic view, so we need to update
if (version_compare('2.0.0', $old_version, '>')) {
$updated_elggx_fivestar_views = array();
$lines = explode("\n", elgg_get_plugin_setting('elggx_fivestar_view', 'elggx_fivestar'));
foreach ($lines as $line) {
if ($line == "elggx_fivestar_view=object/groupforumtopic, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />") {
$line = "elggx_fivestar_view=object/discussion, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />";
}
$updated_elggx_fivestar_views[] = $line;
}
$elggx_fivestar_view = '';
$updated_elggx_fivestar_views = array_filter($updated_elggx_fivestar_views);
$updated_elggx_fivestar_views = array_slice( $updated_elggx_fivestar_views, 0);
if (is_array($updated_elggx_fivestar_views)) {
$elggx_fivestar_view = implode("\n", $updated_elggx_fivestar_views);
}
elgg_set_plugin_setting('elggx_fivestar_view', $elggx_fivestar_view, 'elggx_fivestar');
}
// On Elgg 2.3 the former attribute_value of "elgg-subtext" used in several default fivestar views needs to be updated to
// "elgg-listing-summary-subtitle elgg-subtext"
if (version_compare('2.3.1', $old_version, '>')) {
$updated_elggx_fivestar_views = array();
$lines = explode("\n", elgg_get_plugin_setting('elggx_fivestar_view', 'elggx_fivestar'));
foreach ($lines as $line) {
switch ($line) {
case "elggx_fivestar_view=object/blog, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/blog, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
case "elggx_fivestar_view=object/file, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/file, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
case "elggx_fivestar_view=object/bookmarks, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/bookmarks, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
case "elggx_fivestar_view=object/page_top, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/page_top, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
case "elggx_fivestar_view=object/thewire, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/thewire, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
case "elggx_fivestar_view=group/default, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br>":
$line = "elggx_fivestar_view=groups/profile/summary, tag=div, attribute=class, attribute_value=groups-stats, before_html=<br>";
break;
case "elggx_fivestar_view=object/discussion, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/discussion, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
case "elggx_fivestar_view=object/album, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/album, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
case "elggx_fivestar_view=object/image, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/image, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
case "elggx_fivestar_view=object/izap_videos, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/izap_videos, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
case "elggx_fivestar_view=object/event_calendar, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/event_calendar, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
case "elggx_fivestar_view=object/news, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/news, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
case "elggx_fivestar_view=object/poll, tag=div, attribute=class, attribute_value=elgg-subtext, before_html=<br />":
$line = "elggx_fivestar_view=object/poll, tag=div, attribute=class, attribute_value=elgg-listing-summary-subtitle elgg-subtext, before_html=<br />";
break;
}
$updated_elggx_fivestar_views[] = $line;
}
$elggx_fivestar_view = '';
$updated_elggx_fivestar_views = array_filter($updated_elggx_fivestar_views);
$updated_elggx_fivestar_views = array_slice( $updated_elggx_fivestar_views, 0);
if (is_array($updated_elggx_fivestar_views)) {
$elggx_fivestar_view = implode("\n", $updated_elggx_fivestar_views);
}
elgg_set_plugin_setting('elggx_fivestar_view', $elggx_fivestar_view, 'elggx_fivestar');
}
if (version_compare($new_version, $old_version, '!=')) {
// Set new version
elgg_set_plugin_setting('version', $new_version, 'elggx_fivestar');
}