PHP reddit clone
PHP JavaScript
Switch branches/tags
Nothing to show
Latest commit e7e942d Jan 17, 2012 @Xlator Xlator hm
Permalink
Failed to load latest commit information.
ajax
css
forms add mod_rewrite support (including .htaccess file), reddit style base… Jan 8, 2012
functions
images add comment formatting help and more Dec 31, 2011
js add mod_rewrite support (including .htaccess file), reddit style base… Jan 8, 2012
templates add mod_rewrite support (including .htaccess file), reddit style base… Jan 8, 2012
.gitignore commit Dec 20, 2011
.htaccess add mod_rewrite support (including .htaccess file), reddit style base… Jan 8, 2012
README add mod_rewrite support (including .htaccess file), reddit style base… Jan 8, 2012
README.sv.details.txt add ie css files Dec 31, 2011
comments.php add mod_rewrite support (including .htaccess file), reddit style base… Jan 8, 2012
config.dist.php update readme, add config file Dec 31, 2011
diggit.sql add session id checking, most active users list. RELEASE Dec 31, 2011
index.php add mod_rewrite support (including .htaccess file), reddit style base… Jan 8, 2012
login.php add mod_rewrite support (including .htaccess file), reddit style base… Jan 8, 2012
submit.php hm Jan 17, 2012
user.php add mod_rewrite support (including .htaccess file), reddit style base… Jan 8, 2012

README

/* --------- Comment output functions --------- */
function commentTree($comments,$parent=NULL,$layer=1) :: Builds comment tree, and calls printComment() for each comment in the correct order.
function printComment($comment,$indent) :: Outputs a comment
function parseComment($text) :: Parses comment formatting and sanitizes comment string
function parseQuote($text) :: Callback function for preg_replace for quotes in comments (not working)
function parseCode($text) :: Callback function for preg_replace for code blocks in comments (not working)

/* --------- Common functions (used throughout the site) --------- */
function timeSince($mysqltimestamp) :: returns time since given timestamp, rounded to the largest whole unit (e.g 3 hours 12 minutes ~ 3 hours)
function printHeader() :: Outputs the site header
function voteArrows($myvote,$subjectid) :: Outputs the appropriate voting arrows depending on the logged in user's vote
function pagination($page, $totalpages) :: Pagination function, takes page info from getLinks() / getComments()
function buildQueryString($qs,$suffix=NULL) :: Takes an array from parse_str, returns a query string
function buildLink($url="#", $text="link", $class=NULL, $id=NULL, $name=NULL) :: Construct an internal hyperlink
function simplifyURL($url) :: Rewrite a query string to a static URL
function spanHide() :: Returns a hidden span with the contents of all arguments in order
function urlTitle($str) :: Sanitize link title for URL
function unbase36($str) :: Return decimal value of base 36 encoded number
function base36($int) :: Return base 36 encoding of integer

/* --------- Database connection/query helper functions --------- */
function dbConn() :: Returns database link
function dbQuery($query) :: Returns result of query, logs error and returns false on failure
function dbQueryId($query) :: Returns insert id of query
function dbFirstResult($query) :: Returns first row of query result as indexed array
function dbFirstResultAssoc($query) :: Returns first row of query result as associative array
function dbResultArray($query) :: Returns query result as associative array
function dbResultExists($query) :: Returns true if a result is found, false if it isn't
function dbRowCount($query) :: Returns the number of rows in the query result
function dbEscape($string) :: Returns escaped string to prevent SQL injection attacks
function dbEscapeArray($array) :: Returns escaped array to prevent SQL injection attacks

/* --------- User table functions --------- */
function getUsername($id) :: Returns name of user with given id
function getUserid($username) :: Returns id of user with given name
function getPassword($username) :: Returns password hash of user with given name
function userExists($parameter,$value) :: Checks if a user exists, either by id, email or username
function registerUser($input) :: Writes user info to database on successful registration, returning the user id
function login($sessionid) :: Store session ID in user table
function logout() :: Remove session ID from user table and destroy session
function checkLogin($userid) :: Check session id against user table, logout if the ID is different
function getUser($userid=0) :: Returns an array containing user info, comment/link counts and points

/* --------- Link table functions --------- */
function getLink($id) :: Fetch a single link by id
function getLinks($page=1,$limit=25,$category=NULL,$user=NULL,$domain=NULL) :: Return array containing array of links, the current page and the total number of pages
function linkExists($url) :: Return true if the given URL has already been posted
function linkIdExists($id) :: return true if the link with the given id exists
function domainExists($domain) :: Return true if there are any links with the given domain
function sendLink($input) :: takes an array of sanitized input to insert into the database. On success, returns the id of the submitted link
function deleteLink($linkid) :: Delete link
function nsfw($linkid) :: Toggle nsfw status of link

/* --------- Category table functions --------- */
function categoryExists($cat) :: Return true if the given category exists
function getCategories($limit=0) :: Get an array of categories, optionally only those owned by a specific user

/* --------- Comment table functions --------- */
function sendComment($input) :: Takes an array of sanitized input. Submits comment to database and returns ID.
function getComments($linkid,$user=0,$page=1,$limit=25) :: Returns an array of comments to the given link ID
function rawComment($commentid) :: Returns raw form of comment with given ID (for comment editing)
function deleteComment($commentid) :: Deletes comment with given ID

/* --------- Vote table functions --------- */
function getMyPoints($userid) :: Get given user's total points (from their submissions and comments)
function vote($userid,$subjectid,$type,$vote) :: Enters, removes or edits a vote from user for subject, returns new vote count.

/* --------- Form output functions --------- */
function linkform($errors=array(),$input=array()) :: Outputs the link submission form with error messages and input from previous attempt (if any)
function loginform($errors=array(),$input=array()) :: Outputs the login form with error messages and input from previous attempt (if any)
function regform($errors=array(),$input=array()) :: Outputs the registration form with error messages and input from previous attempts (if any)
function commentform($id=0,$hide=0) :: Outputs a comment form for the given comment id, optionally hidden

/* --------- Link input validation/cleaning functions --------- */
function linkErrors($input) :: Takes an array of link input, returns array of errors (if any) or false on no errors.
function cleanLink($input) :: Takes an array of link data, returns same but sanitized.
function printLink($link) :: Prints a link

/* --------- Password hashing and comparison functions --------- */
function generateSalt($length = 128) :: Generate a hash salt
function hashPassword($password,$salt) :: Hash a password
function validatePassword($password,$storedhash) :: Check an entered password against a stored hash

/* --------- Validation functions --------- */
function registrationErrors($input) :: Validate registration data, return array of errors (if any), else return false
function loginErrors($input) :: Check for errors in the login form

/* --------- User info output functions --------- */
function printUser($user) :: Output user information