Elgg
1.8 Social
Networking
Create, customize,
and
deploy
your very
ownsocial
networking
site
with
Elgg
Cash Costello
open
source*
communityexperiencedistilled
PUBLISHING
BIRMINGHAM-MUMBAI
Table of Contents
Preface 1
Chapter
1: Social Networking andElgg
7Social features 8
Profiles 8
Relationships
8Content
sharing
8Activity
and notifications 8Groups
8Communication 9
What is
Elgg?
9TheElgg engine 10
Usermanagement 11
Privacy
controls 11Theming
11Commenting
12Tagging
12Widgets
12 Internationalization 13 Feeds 13 Web services 14The power of
plugins
14Bundled
plugins
14Third-party plugins 14
Themes 15
Building
yourown plugins 15Case studies 15
Nichesocial network 16
Designingandbuildingthesite 16
Pluginsmentioned 17
Corporate
intranet 17Designingandbuildingthe site 17
Deployingthe site 18
Pluginsmentioned 18
Educational collaboration 18
Designing and buildingthe site 19
Deployingthe site 19
Pluginsmentioned 19
Elgg
resources 20Elgg community
20Elgg wiki 20
Developer
resources 20A few wordsofadvice 20
Take notes 20
Save resources 21
Be methodical 21
Finding help
21Summary
21Chapter
2:Installing Elgg
23Preparing
the server 23Checking requirements
24Downloading
the latest version 24Extracting
the files 25Moving
filesto yourweb serverdirectory
25Configuring
the server 27Create thedatabase 28
Run
Elgg's
installer 29Loading
the database 31Configure Elgg
32Creating
the admin account 33All done! 34
Summary
35Chapter
3: ATour of Your First Elgg Site 37Getting
around 38Registering
users 39User profiles and avatars 40
Profile information 41
Avatar 42
Friends 45
Activity
stream 47 Tools 48Blogs
48 Bookmarks 49 Files 50Groups
50Pages
52Messages
53 The wire 53 Usersettings 54 Yoursettings
54 Tools 55 Notifications 55 Administration 56Activating plugins
58 Sitecategories
58Custom
profile
fields 59Default
widgets
59Site pages 60
Reported
content 61Customizing
yoursite 61User
registration
and authentication 62Widgets
62Friendship
model 62Roles 62
Help
and support 63Summary
63Chapter
4:Sharing
Content 65Blogs
66Creating
ablog
post 67Embedding photosand files 68
Publishing 69
Finding
andviewing
69Search 70
Lists ofblog posts 70
RSS feeds 71
Widget 72
Commenting
72Use cases 73
Bookmarks 74
Adding
a bookmark 74 Bookmarklet 76Viewing
77 Usecases 78 File 79Uploading
afile 79Viewing
80 Use cases 83 Customizations 83 The wire 83Posting
84Viewing
85 Twitterintegration 86 Use cases 89 Customizations 90Summary
9°Chapter
5:Communities, Collaboration,
and Conversation 91Groups
92Creating
a group 92Group profile
94 Membership 95 Discussion forum 96Group
tools 98Finding
groups 99 Usecases 100 Customizations 100Pages
101Creating
pages 102Viewing
103 Usecases 104 Customizations 104Messages
104 Inbox 104Composing
105 Customizations 106Message
board 106 Customizations 108Summary
108Chapter
6:Finding
and Using Plugins 109Plugin
administration 109Filtering
andsorting
109Plugin dependencies
110Plugin settings
113Finding plugins
113Browsing
the repository 115Searching
115Evaluating
beforedownloading
115Look at thepluginoverview 115
Read the comments 115
Check thehistory 116
Custom
plugins
116Installing plugins
116Testserver 117
Copying
the code 117Activating
andconfiguring
117Invalidplugin? 118
Troubleshooting
118Themes 118
Findingand installingthemes 119
Free themes 119
Commercial themes 120
Custom themes 120
Installingthemes 121
Major community plugins
122Tidypics
122 Plugin profile 122 Administration 123 Uploading photos 124 Viewing photos 124 Tagging photos 126 Event calendar 126 Plugin profile 127 Administration 127 Sitecalendar 127 Groupcalendar 128 ProfileManager 128 Plugin profile 128Adding profilefields 129
Configuringtheprofilefields 130
Plugin settings 130
Chapter
7:Creating
Your FirstPlugin
133What you need to know 134
Elgg developer
resources 135Setting
up yourdevelopment
environment 136Editing
code 136Configuring
yoursite 137Hello,
World! 138Plugin
skeleton 138Createyourplugin directory 138
Plugin manifest 139
Startscript 139
Activatingthe hello worldplugin 140
Register
for theinit,
system event 140Adding
a new route 141Creating
a web page 142Update routing
143Add to the site menu 144
Extending
the page handler 145Add a sidebar menu 146
Language
support 148Personalizing the content 149
Organizing
yourcontentinto views 150Agreetingview 151
A stats view 153
Review 155
Debugging
155Debugging
tothelog
156Debugging
to the screen 157Debugging
PHPthrough
an IDE 158Firebug
and other browserdevelopment
tools 159Elgg developer
tools 161Inspect 161
Themingsandbox 162
Summary
162Chapter8: Customization
through Plugins
163Lesson 1:
Changing wording
164Problem 164
Solution 164
Example
164Step1: Create the pluginstructure 165
Step2:Find thelanguage strings 166
Exercise 167
Lesson 2:
Modifying
a section ofa page 167Problem 167
Solution 168
Example
168Step1: Find the view to override 168
Step2: Create thepluginstructure 170
Step3: Edit thelogoview 170
Step4:Stylethe header 172
Exercise 173
Lesson 3:
Adding
newcontent to a page 173Problem 173
Solution 173
Example 174
Step1: Find the view to extend 175
Step2: Create the plugin structure 175
Step3: Buildourview 175
Step4: Make thetipsrandom 176
Exercise 177
Lesson 4:
Doing something
when Xhappens
178Problem 178
Solution 178
Example
178Step 1: Find the event 178
Step2: Create thepluginstructure 179
Step3: Write thefunction thatsends the e-mail 180
Exercise 180
Lesson 5:
Creating
acustomwidget
181Problem 181
Solution 181
Example
181Step1: Create thepluginstructure 182
Step2:Createthewidgetedit view 182
Step3: Create thewidgetcontent view 184
Exercise 186
Lesson 6:
Giving
your usersoptions 186Problem 186
Solution 187
Example
187Step1: Create thepluginstructure 187
Step2: Add usersettings 188
Step3: Create the toolbar view 190
Exercise 192
Lesson 7:
Adding JavaScript
193Problem 193
Solution 193
Example
193Step 1: Create thepluginstructure 194
Step2: Load theJavaScriptfile 194
Step3: Add CSS andJavaScriptinitialization 195
Exercise 196
Lesson 8:
Changing
howElgg
doesX 197Problem 197
Solution 197
Example
197Step1: Create the pluginstructure 198
Step2: Create the index page 199
Step3: Define the views 201
Step4: AddtheCSS 203
Step5: Add aplugin setting 204
Exercise 206
Lesson 9:
Collecting
andstoring
data 207Problem 207
Solution 207
Example
207Overview 208
Step 1: Create thepluginstructure 208
Step2: Create the mainhelppage 209
Step3: Create thecategories 211
Step4:Addanadministrationpage 212
-Step 5: Create the formbody 213
Step6: Create thesaveaction 215
Step7: Create thehelp categorypage 217
Step8: Create thehelp objectview 219
Step9: Add thehelpsidebar 221
Step10: Add CSS for thetopic listingpage 222
Step11: Finish the mainhelppage 223
Exercise 225
Summary
226Chapter
9:Theming Elgg
227What you need to know 228
Theming
basics 228Elgg's
default theme 228HTML 229
CSS 231
JavaScript 232
Views system 233 What isaview? 233 Extendingaview 234 Overridingaview 234 Template language 234 Caching 235 Theviewtype 235 Tools 235 CSS framework 236
Creatingabstractions ofcommon visualpatterns 236
Customizing objects through extension classes 237
Adding
externalJavaScript
and CSS 238Menu system 238
Registeringa menu item 239
Renderinga menu 240
Comparing theming
in WordPresstoElgg
240Building
a theme 241Plugin
structure 242Layout 244
Defaultlayout 244
Pageheader 244
Page bodylayout 244
Pagefooter 245
Movingthe search box 246
Styling
the sidebar module 247Movingthe site menu to thetopbar 248
Creating
a mobile theme 251Plugin
structure 252Layout
253CSS 253
Summary
256Chapter 10:
Moving
to Production 257Selecting
a server 258Performance considerations 258
Competingforresources 258
Usage patterns 259
General guidelinesforserverselection 260
Hosting options
260Sharedhosting 261
Virtual Private Server 261
Dedicatedserver 262
Cloud hosting 262
Hostingcompanyselection 262
Configuring
a server 263PHP 264
MySQL
266Cron 267
E-mail 268
Managing
the site 268Backup
269 Code 269 Database 269 Files 270 Serverconfiguration 270 Restoring 270Log
rotation 270Spam
271 Registration 271 Detectingspammers 272 Webanalytics
273 Dailytasks 273Monitoringuserregistration 273
Reviewing reportedcontent 273
Respondingto feedback 273
Community management 274
Testing, upgrading,
andmoving
a site 274Testing
274Mirroringtheproductionsite 274
Testplan 275
Upgrading
276Moving
asite 277Performance 278
Benchmarking
278Monitoring and data collection 278
Stresstesting 279
Easy performance
gains
280Advanced
performance tuning
andscaling
281Caching 281
Multipleservers 282
Resources 282
Reporting bugs
283Steps
toreproduce
the problem 283Elgg
orplugin?
284Reporting
thebug
284Summary
284Appendix
A:Developer's
QuickStart Guide 285Overview of
Elgg
as a framework 285of
Object-oriented
orprocedural?
286Does itusethe Model-View-Controller
pattern?
286Convention or
configuration?
286Is it extensible? 286
Whattemplate engine is used? 287
A Model-View-Controller
perspective
ofElgg
287Overview 287 Controllers 287 Model 288 Views 289
Routing
290 Code location 290 Actions 290 Code location 290Page
handlers 291 Codelocation 291 Frameworkbooting
291 Code location 292 Data model 292 Entities 292Typeandsubtype 293
GUID 293 Owner 293 Container 293 Access 293 Database 294 Relationships 294 Extenders 294 Database 295 Retrievalfunctions 296 Code location 296 Views 297 Viewtemplates 297
Page
shells andlayout
298View
type
298Overriding
andextending
views 299Special
views 299Code location 299
Events and hooks 300
Elgg
events 300Plugin
hooks 300Plugins
301 Initialization 302Plugin
order 302 Conventions 302 Themes 303 Code location 303Activity
stream 304 Code location 304 Notifications 304 Code location 304Internationalization and localization 305
Code location 305
Lightning round 305
Authentication 306
Caching
306Configuration
306Debugging
andlogging
306JavaScript
307 Menus 307 Privatesettings
307 Search 307Security
308 Sessionhandling
308 Unit tests 308 Web services 308Widgets
308Summary
309Appendix
B: ViewsCatalog
311^
Using
views 311Page
structure 312 Shells 312Layouts
313 Elements 313 Topbar 314 Header 314 Sidebar 314 Footer 315 Owner block 316 Status messages 316 Comments 317 Searchbox 317 Components 318Gallery 318 Imageblock 319 List 319 Module 320
Navigation
321 Breadcrumbs 321Pagination
321 Menus 321 Topbarmenu 322 Sitemenu 322 Pagemenu 322 Footermenu 323Userhovermenu 323
Entitymenu 323 Tabs 324 Forms 324
Input
324 Access 325 Buttons 325 Checkboxes 325 Date 326 Drop-downselector 327 Fileupload 327 Hidden input 327 Largetextarea 328 Password 328 Radio buttons 328 Textbox 329 Userpickers 329Output
330 Date 330 E-mailaddress 330 Link 330 Tagcloud 331 Tags 331 Text 331 The form 331Users,groups, and