Instantly share code, notes, and snippets.
Created
February 15, 2012 17:21
-
Star
0
(0)
You must be signed in to star a gist -
Fork
1
(1)
You must be signed in to fork a gist
-
Save srcoley/1837430 to your computer and use it in GitHub Desktop.
Social Stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 : [email protected]) | |
* | |
* 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() { | |
// A form that asks which events should be tracked | |
// OR | |
// 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 | |
* | |
* We can shortcode this for use inside the WP content editor | |
* OR | |
* 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 | |
} | |
/* | |
* UNINSTALL | |
*/ | |
function socstu_uninstall() { | |
// Delete database table | |
// 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() | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment