Skip to content

Instantly share code, notes, and snippets.

@bluetidepro
Forked from srcoley/social_stuff.php
Created February 15, 2012 17:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluetidepro/1837479 to your computer and use it in GitHub Desktop.
Save bluetidepro/1837479 to your computer and use it in GitHub Desktop.
Social Stuff
<?php
/*
* Plugin Name: Social Stuff
* Description: Allows users to befriend or follow one-another. Also tracks events such as commemts and follows so they they can be displayed in an activity feed.
* Version: 0.1
* Author: Stephen Coley
* Author URI: http://coley.co
* License: GPL2
*
*
* Copyright 2012 srcoley (email : stephen@coley.co)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* FIG. 1
*
* Database Table: wp_socstu_events
*
* event_id (int) 11 not null
* event_action (varchar) 225 not null (follow, unfollow(?), comment, hype, unhype(?))
* event_action_id (int) 11 not null (the id of comment made, post hyped, etc...)
* user_id int 11 not null
* user_2_id int 11 not null (to show where event took place: user_id followed user_2_id; user_id commented on user_2_id 's hype, etc...)
* event_timestamp timestamp not null
*/
/*
* FIG. 2
*
* WP Options
*
* socstu_version_number
* socstu_track - which events to track
*/
/*
* INSTALL
*/
function socstu_install() {
// If Social Stuff is previously installed
// Update database & settings to support new version
// Else if Social Stuff has never been installed
// Create database table(fig. 1)
// Add WP opts(fig. 2)
}
/*
* OPTIONS PAGE
*/
function socstu_options_page() {
// We can skip this and just hardcode your settings in(saves time)
}
/*
* DISPLAYS FOLLOW/UNFOLLOW BUTTON
*
* Displays a button to follow
* or unfollow depending on
* friendship status
*
* You can manually call the php function from within your profile page template
*/
function scostu_follow_button($user_id) {
// IF $user_id and the $logged_in_user_id don't match
// IF socstu_are_friends($user_id, $logged_in_user_id) returns true
// Display unfollow button
// ELSE
// Display follow button
// ELSE IF $user_id and $logged_in_user_id do match
// Display nothing or a message to tell the user that they can't follow themeselves
// Clicking button will trigger an ajax call to socstu_ajax()
}
/*
* PERFORMS THE FOLLOW/UNFOLLOW ACTION VIA AJAX REQUEST
*/
function socstu_ajax() {
// IF user_ids match
// RETURN FALSE
// ELSE
// IF socstu_are_friends
// RETURN FALSE
// ELSE
// Update both user's socstu_follows and socstu_followers meta to include the respective user ids
// RETURN TRUE
}
/*
* DISPLAY ACTIVITY FEED
*
* Doesn't run any queries if the cachefile's
* moddate is younger than 5 minutes (can be any number you specify)
*
* This function will be available within WP templates
*
*/
function socstu_activity_feed() {
// IF cachfile is younger than 5 minutes
// Display cached feed
// ELSE
// Get socstu_follows user meta from logged in user
// Query wp_socstu_events for the last 10 or 20 events with user_ids that match who the user follows
// Start an output variable
// Loop through events
// Add event to output variable
// Cache the output variable
// Display the output variable
}
/*
* ADD EVENT TO DATABASE
*/
function socstu_add_event() {
// IF all data is validated and safe to go into the db
// Build query from args
// IF query runs successfully
// RETURN TRUE
// ELSE
// RETURN FALSE
// ELSE
// REUTNR FALSE
}
/*
* CHECKS IF USERS ARE FRIENDS
*/
function socstu_are_friends($user_1, $user_2) {
// IF $user_1 and $user_2 are friends
// RETURN TRUE
// ELSE
// RETURN FALSE
}
/*
* CHECKS IF USER HAS FOLLOWERS
*/
function socstu_has_followers($user_id) {
// IF $user_id has any followers (followers > 0)
// RETURN TRUE
// ELSE
// RETURN FALSE
}
/*
* DISPLAYS UN-ORDERED LIST OF FOLLOWERS (if they have any)
*/
function socstu_follower_list($user_id) {
// IF $user_id has followers display them in an foreach li form and grab info on each follower
// RETURN TRUE
// ELSE
// RETURN FALSE
}
/*
* UNINSTALL
*/
function socstu_uninstall() {
// Delete database table
// Delete WP opts
}
/*
* IF USER IS DELTED, DELETE THEIR ACTIONS AND REMOVE FROM ANY FOLLOWERS LISTS, ETC
*/
function socstu_deleted_user() {
// Delete all database table entries from that user
// Delete WP opts
}
/*
* ACTIONS
*/
function socstu_actions() {
// Bind our events to the actions and filters provided by WP
// Everytime a comment is made, a post is hyped, a user is followed, run socstu_add_event()
// List of actions we want to track:
// -If someone new follows you
// -If someone un-follows you
// -If someone you follow, follows someone else
// -If someone you follow, un-follows someone else
// -If someone you follow, hypes something
// -If someone you follow, un-hypes something
// -If someone you follow, comments on something
// -If someone you follow, posts a launch (posts a post)
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment