Tutorials > Creating Application Tutorial 1 - Case Study: "Tom Friend" Application

Creating Application Tutorial 1 - "Tom Friend" Application

This tutorial studies the design and implementation of "Tom Friend" application

  1. Objective
  2. Usability Goals
  3. Design
  4. Implementation - Server Side (PHP)
  5. Implementation - Admin Server Side (PHP)
  6. Installer

Objective


Create application that will assign one or more friends to newly signup up users.


Usability goals


The application should be simple to manage by admin


Design



We need to have a unique application name and language variables, the following parameters will identify the application:

  • Application Name/Key: tomfriend
  • Application Hash: 6566ebcd75422bdff5d67ea4cf671904
  • Application Language Range: 100030000 - 100030024 (25 language variables)
    (Note: This is private socialenginemods language range).


The application will use one of the built in SE hooks that is exposed through the apps API, se_signup_success. This hook is called when the new user finishes registration.

Implementation - Server Side (PHP)





<?php

/*
 * Application: Tom Friend
 * Author: SocialEngineMods
 *
 * 
 */

class app_tomfriend extends semods_myapp {

  // this function is called to handle the hook
  function handlehook($hook_name) {
    
    switch($hook_name) {

      case "se_signup_success":
        {
          
          // This is the list of users to befriend as a comma separated string, set using admin interface.
          $befriend_users = $this->app->get_global_setting('befriend','');
        
          if($befriend_users == '')
            return;
          
          // iterate over all "tom friend" users and befriend them with current user (newly signup up)
          $befriend_users = explode(',',$befriend_users);
          
          foreach($befriend_users as $befriend_user) {
          
            $tom_user = new se_user( array( $befriend_user ) );
            
            if($tom_user->user_exists) {
            
              // make a mutual friend connection between "tom friend" and the current user (viewer)
              $this->viewer->user_friend_add($tom_user->user_info['user_id'], 1, '', '');
              $tom_user->user_friend_add($this->viewer->user_info['user_id'], 1, '', '');
              
            }
            
          }
          
        }
        
        break;
    }
    
  }

}

?>

            



Implementation - Admin Side




This has two parts, the template to show settings and the app code to handle the settings

Soon.
          
            



Installer


Some fields explained:
  • pages_admin - this is the title of the admin application tab (shown after main application settings tab).
  • has_user_interface - this application does not show anything to the user and thus don't need the User Interface settings
  • hooks - These are the hooks this application wants to handle



<?xml version="1.0" encoding="UTF-8"?>
<application>
  <version>1.00</version>
  <title>Tom Friend</title>
  <author>SocialEngineMods</author>
  <author>
    <name>SocialEngineMods</name>
    <email>info@socialenginemods.net</email>
    <website>http://www.socialenginemods.net/</website>
  </author>
  <hash>6566ebcd75422bdff5d67ea4cf671904</hash>
  <type>app</type>
  <description><![CDATA[Tom Friend]]></description>
  <pages_admin>100030001</pages_admin>
  <show_in_user_menu>0</show_in_user_menu>
  <has_user_interface>0</has_user_interface>
  <hooks list="true">
    <hook name="se_signup_success"></hook>
  </hooks>
  <languages list="true">
    <language code="en" name="English" list="true">
      <languagevar id="100030000"><![CDATA[Tom Friend]]></languagevar>
      <languagevar id="100030001"><![CDATA[Setup Friends]]></languagevar>
      <languagevar id="100030002"><![CDATA[Application Settings - Tom Friend]]></languagevar>
      <languagevar id="100030003"><![CDATA[Setup who will be the Tom Friend(s) of the new user.]]></languagevar>
      <languagevar id="100030004"><![CDATA[General Settings]]></languagevar>
      <languagevar id="100030005"><![CDATA[Do you want each new user that signs up to your social network to automatically
be friends with another specific user? This feature was made popular by MySpace, wherein
you are automatically friends with "Tom" when you sign up. <br><br>

Instructions: <br><br>
1) Create a new user if necessary. This user will be the one that is automatically made friends with all other new users.
<br><br>
2) Get this user's user ID. You can get this by going to "View Users" in the Admin Panel and finding the username.
The ID is the number in the leftmost column.
<br><br>
3) Enter the ID in the text box above
<br><br>
4) If you want to have multiple users get added as a friends, separate the ID's with commas, like this: 1,2,3. No spaces!
<br>]]></languagevar>
      <languagevar id="100030006"><![CDATA[User ID's:]]></languagevar>
      <languagevar id="100030007"><![CDATA[Save Settings]]></languagevar>
      <languagevar id="100030008"><![CDATA[Saved.]]></languagevar>
      <languagevar id="100030009"><![CDATA[User with ID %d doesn't exist.]]></languagevar>
    </language>
  </languages>
</application>