| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
function sidebar_init() { |
|---|
| 15 |
global $CFG; |
|---|
| 16 |
global $function; |
|---|
| 17 |
global $PAGE; |
|---|
| 18 |
|
|---|
| 19 |
if (!isset($PAGE->sidebar)) { |
|---|
| 20 |
$PAGE->sidebar = array(); |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
$base_path = $CFG->dirroot . 'mod/sidebar/'; |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
$function['init'][] = $base_path . 'default_templates.php'; |
|---|
| 28 |
|
|---|
| 29 |
$function['userdetails:edit:details'][] = $base_path . 'lib/userdetails_edit.php'; |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
$PAGE->sidebar_legacy = array(); |
|---|
| 33 |
|
|---|
| 34 |
$PAGE->sidebar_legacy['sidebar-profile'] = array(10, true); |
|---|
| 35 |
$function['sidebar-profile'][] = $CFG->dirroot . 'mod/display/lib/function_log_on_pane.php'; |
|---|
| 36 |
|
|---|
| 37 |
$PAGE->sidebar_legacy['sidebar-stats'] = 50; |
|---|
| 38 |
$function['sidebar-stats'][] = $CFG->dirroot . 'mod/users/lib/function_number_of_users.php'; |
|---|
| 39 |
|
|---|
| 40 |
$PAGE->sidebar_legacy['sidebar-blog'] = array(30, true); |
|---|
| 41 |
$function['sidebar-blog'][] = $CFG->dirroot . 'mod/blog/lib/weblogs_user_info_menu.php'; |
|---|
| 42 |
|
|---|
| 43 |
$PAGE->sidebar_legacy['sidebar-friends'] = array(40, true); |
|---|
| 44 |
$function['sidebar-friends'][] = $CFG->dirroot . 'mod/friend/lib/profile_friends.php'; |
|---|
| 45 |
|
|---|
| 46 |
$PAGE->sidebar_legacy['sidebar-communities'] = array(50, true); |
|---|
| 47 |
$function['sidebar-communities'][] = $CFG->dirroot . 'mod/community/lib/community_memberships.php'; |
|---|
| 48 |
|
|---|
| 49 |
$PAGE->sidebar_legacy['sidebar-owned-communities'] = array(60, true); |
|---|
| 50 |
$function['sidebar-owned-communities'][] = $CFG->dirroot . 'mod/community/lib/communities_owned.php'; |
|---|
| 51 |
|
|---|
| 52 |
$PAGE->sidebar_legacy['sidebar-files'] = array(60, true); |
|---|
| 53 |
$function['sidebar-files'][] = $CFG->dirroot . 'mod/file/lib/files_user_info_menu.php'; |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
if (is_readable($CFG->dirroot . 'mod/category/category_sidebar.php')) { |
|---|
| 57 |
$PAGE->sidebar_legacy['sidebar-blogcats'] = array(30, true); |
|---|
| 58 |
$function['sidebar-blogcats'][] = $CFG->dirroot . 'mod/category/category_sidebar.php'; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
if (is_readable($CFG->dirroot . 'mod/vanillaforum/lib/user_info_menu.php')) { |
|---|
| 62 |
$PAGE->sidebar_legacy['sidebar-vanilla'] = 25; |
|---|
| 63 |
$function['sidebar-vanilla'][] = $CFG->dirroot . 'mod/vanillaforum/lib/user_info_menu.php'; |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
function sidebar_pagesetup() { |
|---|
| 72 |
global $function; |
|---|
| 73 |
global $PAGE; |
|---|
| 74 |
|
|---|
| 75 |
$runned = array(); |
|---|
| 76 |
|
|---|
| 77 |
if (is_array($PAGE->sidebar_legacy)) { |
|---|
| 78 |
foreach ($PAGE->sidebar_legacy as $key => $block) { |
|---|
| 79 |
if (is_array($block)) { |
|---|
| 80 |
$weight = $block[0]; |
|---|
| 81 |
$userdetails = $block[1]; |
|---|
| 82 |
} else { |
|---|
| 83 |
$weight = $block; |
|---|
| 84 |
$userdetails = false; |
|---|
| 85 |
} |
|---|
| 86 |
$label = str_replace('sidebar', '', str_replace('-', ' ', $key)); |
|---|
| 87 |
sidebar_add($weight, $key, sidebar_legacy_wrap(run($key)), true, $label); |
|---|
| 88 |
$runned[] = $function[$key]; |
|---|
| 89 |
|
|---|
| 90 |
} |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
if (isset($function['display:sidebar'])) { |
|---|
| 95 |
foreach ($function['display:sidebar'] as $n => $script) { |
|---|
| 96 |
if (!in_arrayr($script, $runned)) { |
|---|
| 97 |
|
|---|
| 98 |
$function["sidebar:$n"][] = $script; |
|---|
| 99 |
|
|---|
| 100 |
sidebar_add(99, "sidebar-$n", sidebar_legacy_wrap(run("sidebar:$n"))); |
|---|
| 101 |
|
|---|
| 102 |
unset($function["sidebar:$n"]); |
|---|
| 103 |
} |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
$function['display:sidebar'] = array(dirname(__FILE__) . '/lib/sidebar_display.php'); |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
function sidebar_add($weight, $id, $body, $userdetails=false, $label=null, $class=null) { |
|---|
| 122 |
global $PAGE; |
|---|
| 123 |
|
|---|
| 124 |
if (isset($PAGE->sidebar_locked) && !in_array($id, $PAGE->sidebar_locked)) { |
|---|
| 125 |
return; |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
if (!isset($PAGE->sidebar[$weight])) { |
|---|
| 129 |
$PAGE->sidebar[$weight] = array(); |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
if (!isset($PAGE->sidebar_blacklist)) { |
|---|
| 133 |
$PAGE->sidebar_blacklist = array(); |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
if (!in_array($id, $PAGE->sidebar_blacklist) && (!empty($body) || is_callable($id))) { |
|---|
| 137 |
|
|---|
| 138 |
$PAGE->sidebar[$weight][] = array( |
|---|
| 139 |
'id' => $id, |
|---|
| 140 |
'class' => $class, |
|---|
| 141 |
'body' => $body, |
|---|
| 142 |
'userdetails' => $userdetails, |
|---|
| 143 |
'label' => $label, |
|---|
| 144 |
); |
|---|
| 145 |
} |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
function sidebar_remove($id, $overrideall=false) { |
|---|
| 155 |
global $PAGE; |
|---|
| 156 |
|
|---|
| 157 |
if (empty($id)) { |
|---|
| 158 |
trigger_error(__FUNCTION__.": invalid argument (id: empty)", E_USER_ERROR); |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
if ($overrideall) { |
|---|
| 162 |
|
|---|
| 163 |
$block = array(); |
|---|
| 164 |
if (!is_array($id)) $id = array($id); |
|---|
| 165 |
|
|---|
| 166 |
foreach ($PAGE->sidebar as $w => $v) { |
|---|
| 167 |
foreach ($v as $e) { |
|---|
| 168 |
|
|---|
| 169 |
if (in_array($e['id'], $id)) { |
|---|
| 170 |
while (isset($block[$w])) {$w++;} |
|---|
| 171 |
$block[$w] = $e; |
|---|
| 172 |
} |
|---|
| 173 |
} |
|---|
| 174 |
} |
|---|
| 175 |
if (!empty($block)) { |
|---|
| 176 |
unset($PAGE->sidebar); |
|---|
| 177 |
foreach ($block as $w => $b) { |
|---|
| 178 |
sidebar_add($w, $b['id'], $b['body'], $b['userdetails'], $b['label'], $b['class']); |
|---|
| 179 |
} |
|---|
| 180 |
} |
|---|
| 181 |
$PAGE->sidebar_locked = $id; |
|---|
| 182 |
|
|---|
| 183 |
return; |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
if (!isset($PAGE->sidebar_blacklist)) { |
|---|
| 187 |
$PAGE->sidebar_blacklist = array(); |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
if (is_array($id)) { |
|---|
| 191 |
foreach ($id as $e) { |
|---|
| 192 |
sidebar_remove($e); |
|---|
| 193 |
} |
|---|
| 194 |
} |
|---|
| 195 |
|
|---|
| 196 |
elseif (!in_array($id, $PAGE->sidebar_blacklist)) { |
|---|
| 197 |
$PAGE->sidebar_blacklist[] = $id; |
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
if (!empty($PAGE->sidebar) && is_array($PAGE->sidebar)) { |
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
$sidebar = array(); |
|---|
| 204 |
|
|---|
| 205 |
foreach ($PAGE->sidebar as $w => $blocks) { |
|---|
| 206 |
if (!isset($sidebar[$w])) { |
|---|
| 207 |
$sidebar[$w] = array(); |
|---|
| 208 |
} |
|---|
| 209 |
|
|---|
| 210 |
foreach ($blocks as $block) { |
|---|
| 211 |
if ($block['id'] == $id) { |
|---|
| 212 |
continue; |
|---|
| 213 |
} else { |
|---|
| 214 |
$sidebar[$w][] = $block; |
|---|
| 215 |
} |
|---|
| 216 |
} |
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
$PAGE->sidebar = $sidebar; |
|---|
| 221 |
if (isset($PAGE->sidebar_locked)) { |
|---|
| 222 |
|
|---|
| 223 |
unset($PAGE->sidebar_locked); |
|---|
| 224 |
} |
|---|
| 225 |
} |
|---|
| 226 |
} |
|---|
| 227 |
} |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
function sidebar_get_blocks() { |
|---|
| 235 |
global $PAGE; |
|---|
| 236 |
|
|---|
| 237 |
$result = array(); |
|---|
| 238 |
if (!empty($PAGE->sidebar) && is_array($PAGE->sidebar)) { |
|---|
| 239 |
foreach ($PAGE->sidebar as $w => $blocks) { |
|---|
| 240 |
foreach ($blocks as $b) { |
|---|
| 241 |
if ($b['userdetails'] === true) { |
|---|
| 242 |
$result[] = $b; |
|---|
| 243 |
} |
|---|
| 244 |
} |
|---|
| 245 |
} |
|---|
| 246 |
} |
|---|
| 247 |
|
|---|
| 248 |
return $result; |
|---|
| 249 |
} |
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
function sidebar_display() { |
|---|
| 257 |
global $PAGE; |
|---|
| 258 |
|
|---|
| 259 |
$body = ''; |
|---|
| 260 |
|
|---|
| 261 |
if (!empty($PAGE->sidebar) && is_array($PAGE->sidebar)) { |
|---|
| 262 |
$sidebar = $PAGE->sidebar; |
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
ksort($sidebar); |
|---|
| 266 |
|
|---|
| 267 |
foreach ($sidebar as $w => $blocks) { |
|---|
| 268 |
foreach ($blocks as $block) { |
|---|
| 269 |
if (user_flag_get('sidebar'.$block['id'], page_owner()) != 'no') { |
|---|
| 270 |
|
|---|
| 271 |
if (empty($block['body']) && is_callable($block['id'])) { |
|---|
| 272 |
|
|---|
| 273 |
$block_body = $block['id'](); |
|---|
| 274 |
} else { |
|---|
| 275 |
$block_body = $block['body']; |
|---|
| 276 |
} |
|---|
| 277 |
|
|---|
| 278 |
$body .= templates_draw(array( |
|---|
| 279 |
'context' => 'sidebar:block', |
|---|
| 280 |
'id' => $block['id'], |
|---|
| 281 |
'class' => $block['class'], |
|---|
| 282 |
'body' => $block_body, |
|---|
| 283 |
)); |
|---|
| 284 |
} |
|---|
| 285 |
} |
|---|
| 286 |
} |
|---|
| 287 |
} |
|---|
| 288 |
|
|---|
| 289 |
return templates_draw(array( |
|---|
| 290 |
'context' => 'sidebar:wrap', |
|---|
| 291 |
'body' => $body, |
|---|
| 292 |
)); |
|---|
| 293 |
} |
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
function sidebar_legacy_wrap($body) { |
|---|
| 302 |
|
|---|
| 303 |
return preg_replace("#^\s*(<li|<li\s+[\"\'\w-_\.\s\=]*\s*)>(.*)</li>\s*$#si", "\${2}", $body); |
|---|
| 304 |
} |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
if (!function_exists('in_arrayr')) { |
|---|
| 308 |
function in_arrayr($needle, $haystack) { |
|---|
| 309 |
foreach ($haystack as $v) { |
|---|
| 310 |
if ($needle == $v) { |
|---|
| 311 |
return true; |
|---|
| 312 |
} elseif (is_array($v)) { |
|---|
| 313 |
if (in_arrayr($needle, $v) === true) { |
|---|
| 314 |
return true; |
|---|
| 315 |
} |
|---|
| 316 |
} |
|---|
| 317 |
} |
|---|
| 318 |
|
|---|
| 319 |
return false; |
|---|
| 320 |
} |
|---|
| 321 |
} |
|---|
| 322 |
|
|---|
| 323 |
?> |
|---|
| 324 |
|
|---|