diff options
| author | Starla Insigna <hatkirby@fourisland.com> | 2008-11-19 17:27:03 -0500 | 
|---|---|---|
| committer | Starla Insigna <hatkirby@fourisland.com> | 2008-11-19 17:27:03 -0500 | 
| commit | 24503e3abe705acde2df159aeae61be0d009f92e (patch) | |
| tree | 8debbd53dcd0db2f5934c5e2af4e697e3787781d /includes/functions.php | |
| download | fourisland-24503e3abe705acde2df159aeae61be0d009f92e.tar.gz fourisland-24503e3abe705acde2df159aeae61be0d009f92e.tar.bz2 fourisland-24503e3abe705acde2df159aeae61be0d009f92e.zip  | |
Imported sources
Diffstat (limited to 'includes/functions.php')
| -rw-r--r-- | includes/functions.php | 244 | 
1 files changed, 244 insertions, 0 deletions
| diff --git a/includes/functions.php b/includes/functions.php new file mode 100644 index 0000000..c377c29 --- /dev/null +++ b/includes/functions.php | |||
| @@ -0,0 +1,244 @@ | |||
| 1 | <?php | ||
| 2 | /* | ||
| 3 | 444444444 | ||
| 4 | 4::::::::4 | ||
| 5 | 4:::::::::4 | ||
| 6 | 4::::44::::4 | ||
| 7 | 4::::4 4::::4 Four Island | ||
| 8 | 4::::4 4::::4 | ||
| 9 | 4::::4 4::::4 Written and maintained by Starla Insigna | ||
| 10 | 4::::444444::::444 | ||
| 11 | 4::::::::::::::::4 includes/functions.php | ||
| 12 | 4444444444:::::444 | ||
| 13 | 4::::4 Please do not use, reproduce or steal the | ||
| 14 | 4::::4 contents of this file without explicit | ||
| 15 | 4::::4 permission from Hatkirby. | ||
| 16 | 44::::::44 | ||
| 17 | 4::::::::4 | ||
| 18 | 4444444444 | ||
| 19 | */ | ||
| 20 | |||
| 21 | if (!defined('S_INCLUDE_FILE')) {define('S_INCLUDE_FILE',1);} | ||
| 22 | |||
| 23 | require('headerproc.php'); | ||
| 24 | |||
| 25 | function isLoggedIn() | ||
| 26 | { | ||
| 27 | return sess_exists('uname'); | ||
| 28 | } | ||
| 29 | |||
| 30 | function getUserlevel() | ||
| 31 | { | ||
| 32 | if (isLoggedIn()) | ||
| 33 | { | ||
| 34 | $getuser = "SELECT * FROM users WHERE username = \"" . sess_get('uname') . "\""; | ||
| 35 | $getuser2 = mysql_query($getuser); | ||
| 36 | $getuser3 = mysql_fetch_array($getuser2); | ||
| 37 | return $getuser3['user_group']; | ||
| 38 | } else { | ||
| 39 | return 4; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | function countRows($table, $extra = '') | ||
| 44 | { | ||
| 45 | $cntrows = "SELECT * FROM " . $table . " " . $extra; | ||
| 46 | $cntrows2 = mysql_query($cntrows); | ||
| 47 | $i=0; | ||
| 48 | while ($cntrows3[$i] = mysql_fetch_array($cntrows2)) | ||
| 49 | { | ||
| 50 | $i++; | ||
| 51 | } | ||
| 52 | return $i; | ||
| 53 | } | ||
| 54 | |||
| 55 | function generateError($error) | ||
| 56 | { | ||
| 57 | ob_end_clean(); | ||
| 58 | ob_start(); | ||
| 59 | $errorid = $error; | ||
| 60 | include('pages/error.php'); | ||
| 61 | } | ||
| 62 | |||
| 63 | function echoLogData() | ||
| 64 | { | ||
| 65 | if (!isLoggedIn()) { | ||
| 66 | return('Login'); | ||
| 67 | } else { | ||
| 68 | return('Logout'); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | function dispIfNotOld($datTim) | ||
| 73 | { | ||
| 74 | if (($datTim+604800) >= time()) | ||
| 75 | { | ||
| 76 | return('<IMG SRC="/theme/images/icons/new.png" ALT="New!" BORDER="0" WIDTH=16 HEIGHT=16 STYLE="vertical-align: middle;">'); | ||
| 77 | } else { | ||
| 78 | return; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | function getpercent($getpoll3,$num) | ||
| 83 | { | ||
| 84 | $maxper = ($getpoll3['clicks1'] + $getpoll3['clicks2'] + $getpoll3['clicks3'] + $getpoll3['clicks4']); | ||
| 85 | $percent = round(($getpoll3['clicks' . $num] / $maxper) * 100); | ||
| 86 | return($percent); | ||
| 87 | } | ||
| 88 | |||
| 89 | function generateSlug($title,$table) | ||
| 90 | { | ||
| 91 | $title = preg_replace('/[^A-Za-z0-9]/','-',$title); | ||
| 92 | $title = preg_replace('/-{2,}/','-',$title); | ||
| 93 | if (substr($title,0,1) == '-') | ||
| 94 | { | ||
| 95 | $title = substr($title,1); | ||
| 96 | } | ||
| 97 | if (substr($title,strlen($title)-1,1) == '-') | ||
| 98 | { | ||
| 99 | $title = substr($title,0,strlen($title)-1); | ||
| 100 | } | ||
| 101 | $title = strtolower($title); | ||
| 102 | |||
| 103 | $getprevs = "SELECT COUNT(*) FROM " . $table . " WHERE slug = \"" . $title . "\" OR slug LIKE \"" . $title . "-%\""; | ||
| 104 | $getprevs2 = mysql_query($getprevs); | ||
| 105 | @$getprevs3 = mysql_fetch_array($getprevs2); | ||
| 106 | if ($getprevs3[0] > 0) | ||
| 107 | { | ||
| 108 | $title .= '-' . ($getprevs3[0]+1); | ||
| 109 | } | ||
| 110 | |||
| 111 | return($title); | ||
| 112 | } | ||
| 113 | |||
| 114 | function postBlogPost($title,$author,$tag1,$tag2,$tag3,$content) | ||
| 115 | { | ||
| 116 | $slug = generateSlug($title,'updates'); | ||
| 117 | |||
| 118 | $inspost = "INSERT INTO updates (title,slug,author,tag1,tag2,tag3,text) VALUES (\"" . $title . "\",\"" . $slug . "\",\"" . $author . "\",\"" . $tag1 . "\",\"" . $tag2 . "\",\"" . $tag3 . "\",\"" . addslashes($content) . "\")"; | ||
| 119 | $inspost2 = mysql_query($inspost); | ||
| 120 | |||
| 121 | $upconf = "UPDATE config SET value = \"" . date('md') . "\" WHERE name = \"lastUpdate\""; | ||
| 122 | $upconf2 = mysql_query($upconf); | ||
| 123 | |||
| 124 | preg_match_all('|<a\s[^>]*href="([^"]+)"|i', parseBBCode($content), $matches); | ||
| 125 | |||
| 126 | foreach ($matches[1] as $link) | ||
| 127 | { | ||
| 128 | if ($all_links[$link]) | ||
| 129 | { | ||
| 130 | continue; | ||
| 131 | } | ||
| 132 | |||
| 133 | $all_links[$link] = true; | ||
| 134 | |||
| 135 | if (preg_match('/^https{0,1}:/i', $link)) | ||
| 136 | { | ||
| 137 | $c = curl_init(); | ||
| 138 | curl_setopt($c, CURLOPT_URL, $link); | ||
| 139 | curl_setopt($c, CURLOPT_RETURNTRANSFER, true); | ||
| 140 | curl_setopt($c, CURLOPT_HEADER, false); | ||
| 141 | $page_data = curl_exec($c); | ||
| 142 | curl_close($c); | ||
| 143 | |||
| 144 | if (preg_match('/<LINK REL="pingback" HREF="([^"]+)"/i',$page_data,$server)) | ||
| 145 | { | ||
| 146 | $client = new xmlrpc_client($server[1]); | ||
| 147 | $msg = new xmlrpcmsg("pingback.ping", array( new xmlrpcval('http://www.fourisland.com/blog/' . $slug . '/', 'string'), | ||
| 148 | new xmlrpcval($link, 'string'))); | ||
| 149 | $client->send($msg); | ||
| 150 | } | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | $client = new xmlrpc_client('http://rpc.pingomatic.com'); | ||
| 155 | $msg = new xmlrpcmsg("weblogUpdates.ping", array( new xmlrpcval('Four Island', 'string'), | ||
| 156 | new xmlrpcval('http://www.fourisland.com/', 'string'))); | ||
| 157 | $client->send($msg); | ||
| 158 | } | ||
| 159 | |||
| 160 | function recalcPop($id) | ||
| 161 | { | ||
| 162 | $getpost = "SELECT * FROM updates WHERE id = " . $id; | ||
| 163 | $getpost2 = mysql_query($getpost); | ||
| 164 | $getpost3 = mysql_fetch_array($getpost2); | ||
| 165 | $popularity = $getpost3['home_views']; | ||
| 166 | $popularity += ($getpost3['views']*2); | ||
| 167 | $popularity += ($getpost3['rating']*5); | ||
| 168 | |||
| 169 | $getcomments = "SELECT COUNT(*) FROM comments WHERE page_id = \"updates-" . $id . "\" AND username <> \"Pingback\""; | ||
| 170 | $getcomments2 = mysql_query($getcomments); | ||
| 171 | $getcomments3 = mysql_fetch_array($getcomments2); | ||
| 172 | $popularity += ($getcomments3[0] * 10); | ||
| 173 | |||
| 174 | $getpings = "SELECT COUNT(*) FROM comments WHERE page_id = \"updates-" . $id . "\" AND username = \"Pingback\""; | ||
| 175 | $getpings2 = mysql_query($getpings); | ||
| 176 | $getpings3 = mysql_fetch_array($getpings2); | ||
| 177 | $popularity += ($getpings3[0] * 25); | ||
| 178 | |||
| 179 | $setpost = "UPDATE updates SET popularity = " . $popularity . " WHERE id = " . $id; | ||
| 180 | $setpost2 = mysql_query($setpost); | ||
| 181 | } | ||
| 182 | |||
| 183 | function updatePop($id, $area, $plus=1) | ||
| 184 | { | ||
| 185 | $gettrack = "SELECT * FROM tracking WHERE ip = \"" . $_SERVER['REMOTE_ADDR'] . "\""; | ||
| 186 | $gettrack2 = mysql_query($gettrack); | ||
| 187 | $gettrack3 = mysql_fetch_array($gettrack2); | ||
| 188 | |||
| 189 | $trackArr = explode(',',$gettrack3[$area]); | ||
| 190 | |||
| 191 | if (($gettrack3['ip'] != $_SERVER['REMOTE_ADDR']) || (array_search($id,$trackArr) === FALSE)) | ||
| 192 | { | ||
| 193 | $setpost = "UPDATE updates SET " . $area . " = " . $area . "+" . $plus . " WHERE id = " . $id; | ||
| 194 | $setpost2 = mysql_query($setpost); | ||
| 195 | recalcPop($id); | ||
| 196 | |||
| 197 | if ($gettrack3['ip'] == $_SERVER['REMOTE_ADDR']) | ||
| 198 | { | ||
| 199 | $settrack = "UPDATE tracking SET " . $area . " = \"" . $gettrack3[$area] . "," . $id . "\" WHERE id = " . $gettrack3['id']; | ||
| 200 | } else { | ||
| 201 | $settrack = "INSERT INTO tracking (ip," . $area . ") VALUES (\"" . $_SERVER['REMOTE_ADDR'] . "\",\"" . $id . "\")"; | ||
| 202 | } | ||
| 203 | $settrack2 = mysql_query($settrack) or die($settrack); | ||
| 204 | return 1; | ||
| 205 | } else { | ||
| 206 | return 0; | ||
| 207 | } | ||
| 208 | } | ||
| 209 | |||
| 210 | function verifyUser($username, $password) | ||
| 211 | { | ||
| 212 | $getuser = 'SELECT * FROM users WHERE username = "' . $username . '" AND user_password = "' . md5($password) . '"'; | ||
| 213 | $getuser2 = mysql_query($getuser); | ||
| 214 | $getuser3 = mysql_fetch_array($getuser2); | ||
| 215 | return (($_POST['username'] != '') && ($getuser3['username'] == $_POST['username'])); | ||
| 216 | } | ||
| 217 | |||
| 218 | function updateCommentPop($id, $plus=1) | ||
| 219 | { | ||
| 220 | $gettrack = "SELECT * FROM tracking_comments WHERE ip = \"" . $_SERVER['REMOTE_ADDR'] . "\""; | ||
| 221 | $gettrack2 = mysql_query($gettrack); | ||
| 222 | $gettrack3 = mysql_fetch_array($gettrack2); | ||
| 223 | |||
| 224 | $trackArr = explode(',',$gettrack3['comment_id']); | ||
| 225 | |||
| 226 | if (($gettrack3['ip'] != $_SERVER['REMOTE_ADDR']) || (array_search($id,$trackArr) === FALSE)) | ||
| 227 | { | ||
| 228 | $setcomment = "UPDATE comments SET rating = rating+" . $plus . " WHERE id = " . $id; | ||
| 229 | $setcomment2 = mysql_query($setcomment); | ||
| 230 | |||
| 231 | if ($gettrack3['ip'] == $_SERVER['REMOTE_ADDR']) | ||
| 232 | { | ||
| 233 | $settrack = "UPDATE tracking SET rating = \"" . $gettrack3['comment_id'] . "," . $id . "\" WHERE id = " . $gettrack3['id']; | ||
| 234 | } else { | ||
| 235 | $settrack = "INSERT INTO tracking (ip,rating) VALUES (\"" . $_SERVER['REMOTE_ADDR'] . "\",\"" . $id . "\")"; | ||
| 236 | } | ||
| 237 | $settrack2 = mysql_query($settrack) or die($settrack); | ||
| 238 | return 1; | ||
| 239 | } else { | ||
| 240 | return 0; | ||
| 241 | } | ||
| 242 | } | ||
| 243 | |||
| 244 | ?> | ||
