cob05 / diggit Goto Github PK
View Code? Open in Web Editor NEWThis project forked from xlator/diggit
PHP reddit clone
This project forked from xlator/diggit
PHP reddit clone
/* --------- 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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.