Browse Source

initial code

themage
theMage 6 years ago
parent
commit
ddd3415f90
3 changed files with 143 additions and 0 deletions
  1. 5 0
      languages/en.php
  2. 18 0
      manifest.xml
  3. 120 0
      start.php

+ 5 - 0
languages/en.php

@ -0,0 +1,5 @@
1
<?php
2
3
return array(
4
  'profile:about' => 'About <b>%s</b>',
5
);

+ 18 - 0
manifest.xml

@ -0,0 +1,18 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
3
  <name>Avid Profile</name>
4
  <id>avid-profiles</id>
5
  <description>An alternative user profile</description>
6
  <author>MagickSource by AvidMind</author>
7
  <version>0.1</version>
8
  <category>social</category>
9
  <category>profile</category>
10
  <website>http://magick-source.net/for-elgg/avid-profiles/</website>
11
  <copyright>GPL v3</copyright>
12
  <license>GNU General Public License Version 3</license>
13
  <requires>
14
    <type>elgg_release</type>
15
    <version>1.9</version>
16
  </requires>
17
</plugin_manifest>
18

+ 120 - 0
start.php

@ -0,0 +1,120 @@
1
<?php
2
/**
3
 * AvidMind Profile plugin for elgg
4
 *
5
 * @package avid-profiles
6
 */
7
8
elgg_register_event_handler('init', 'system', 'avidprofile_init', 1);
9
10
register_metadata_as_independent('user');
11
12
function avidprofile_init() {
13
  elgg_register_plugin_hook_handler('entity:url', 'user', 'avidprofile_set_url');
14
  elgg_register_plugin_hook_handler('entity:icon:url', 'user','avidprofile_set_icon_url');
15
  elgg_register_plugin_hook_handler('entity:icon:url', 'user','avidprofile_set_icon_url_fallback', 1000);
16
17
  # we don't want the default icon url handler, as it ignores any other
18
  # setting - which makes it hard to chain handlers
19
  elgg_unregister_plugin_hook_handler('entity:icon:url', 'user','user_avatar_hook');
20
21
  elgg_register_page_handler('u', 'avidprofile_page_handler');
22
23
  elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'avidprofile_owner_block_menu');
24
25
}
26
27
function avidprofile_page_handler($page) {
28
  if (isset($page[0])) {
29
    $username = $page[0];
30
    $user = get_user_by_username($username);
31
    elgg_set_page_owner_guid($user->guid);
32
33
  } elseif (elgg_is_logged_in()) {
34
    forward(elgg_get_logged_in_user_entity()->getURL());
35
  }
36
37
  
38
39
  // short circuit if invalid or banned username
40
  if (!$user || ($user->isBanned() && !elgg_is_admin_logged_in())) {
41
    register_error(elgg_echo('profile:notfound'));
42
    forward();
43
  }
44
45
  $action = NULL;
46
  if (isset($page[1])) {
47
    $action = $page[1];
48
  }
49
50
  $content = '';
51
  if ($action == 'edit') {
52
    $base_dir = elgg_get_root_path();
53
    require "{$base_dir}pages/profile/edit.php";
54
    return true;
55
56
  } elseif ($action === NULL and function_exists('avidelgg_list_stream')) {
57
    $content = avidelgg_list_stream(array(users=>array($user)));
58
    
59
  } else {
60
    $content = elgg_view('profile/about', array('entity' => $user));
61
    
62
  }
63
64
  $body = elgg_view_layout('one_sidebar', array(
65
    'content' => $content
66
  ));
67
  echo elgg_view_page($user->name, $body);
68
  return true;
69
}
70
71
function avidprofile_owner_block_menu($hook, $type, $return, $params) {
72
  elgg_log('avidprofile_owner_block_menu');
73
  if (elgg_instanceof($params['entity'], 'user')) {
74
    $luser = elgg_get_logged_in_user_entity();
75
    $owner = $params['entity'];
76
    if (function_exists('avidelgg_list_stream')) {
77
      $url  = "u/{$owner->username}/about";
78
      $item = new ElggMenuItem('profile_about',
79
          elgg_echo('profile:about',
80
              array('user'=>$owner->name)),
81
          $url);
82
      $result[] = $item;
83
    }
84
  }
85
86
  return $result;
87
}
88
89
function avidprofile_set_url($hook, $type, $url, $params) {
90
  $user = $params['entity'];
91
92
  return 'u/'.$user->username;
93
}
94
95
function avidprofile_set_icon_url($hook, $type, $url, $params) {
96
  if ($url) {
97
    return;
98
  }
99
100
  $user = $params['entity'];
101
  $size = $params['size'];
102
103
  $user_guid = $user->getGUID();
104
  $icon_time = $user->icontime;
105
106
  if (!$icon_time) {
107
    return;
108
  }
109
110
  return "avatar/view/$user->username/$size/$user->icontime";
111
}
112
113
function avidprofile_set_icon_url_fallback($hook, $type, $url, $params) {
114
  if ($url) {
115
    return;
116
  }
117
118
  $size = $params['size'];
119
  return "_graphics/icons/user/default{$size}.gif";
120
}