mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
init
This commit is contained in:
3
classes/.htaccess
Normal file
3
classes/.htaccess
Normal file
@@ -0,0 +1,3 @@
|
||||
Options -Indexes
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
81
classes/class_advertisement.php
Normal file
81
classes/class_advertisement.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
class ADVERTISEMENT{
|
||||
var $userid;
|
||||
var $showad;
|
||||
var $userrow = array();
|
||||
var $adrow = array();
|
||||
|
||||
function __construct($userid) {
|
||||
$this->userid = $userid;
|
||||
$this->set_userrow();
|
||||
$this->set_showad();
|
||||
$this->set_adrow();
|
||||
}
|
||||
|
||||
function set_userrow()
|
||||
{
|
||||
$userid = $this->userid;
|
||||
$row = get_user_row($userid);
|
||||
$this->userrow = $row;
|
||||
}
|
||||
|
||||
function enable_ad()
|
||||
{
|
||||
global $enablead_advertisement;
|
||||
if ($enablead_advertisement == 'yes')
|
||||
return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
function show_ad()
|
||||
{
|
||||
if (!$this->enable_ad())
|
||||
return false;
|
||||
else
|
||||
{
|
||||
if ($this->userrow['noad'] == 'yes')
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function set_showad()
|
||||
{
|
||||
$showad = $this->show_ad();
|
||||
$this->showad = $showad;
|
||||
}
|
||||
|
||||
function set_adrow()
|
||||
{
|
||||
global $Cache;
|
||||
if (!$arr = $Cache->get_value('current_ad_array'))
|
||||
{
|
||||
$now = date("Y-m-d H:i:s");
|
||||
$validpos = $this->get_validpos();
|
||||
foreach ($validpos as $pos)
|
||||
{
|
||||
$res = sql_query("SELECT code FROM advertisements WHERE enabled=1 AND position=".sqlesc($pos)." AND (starttime IS NULL OR starttime < ".sqlesc($now).") AND (endtime IS NULL OR endtime > ".sqlesc($now).") ORDER BY displayorder ASC, id DESC LIMIT 10") or sqlerr(__FILE__, __LINE__);
|
||||
$adarray = array();
|
||||
while($row = mysql_fetch_array($res))
|
||||
$adarray[]=$row['code'];
|
||||
$arr[$pos]=$adarray;
|
||||
}
|
||||
$Cache->cache_value('current_ad_array', $arr, 3600);
|
||||
}
|
||||
$this->adrow=$arr;
|
||||
}
|
||||
|
||||
function get_validpos()
|
||||
{
|
||||
return array('header', 'footer', 'belownav', 'belowsearchbox', 'torrentdetail', 'comment', 'interoverforums', 'forumpost', 'popup');
|
||||
}
|
||||
function get_ad($pos)
|
||||
{
|
||||
$validpos = $this->get_validpos();
|
||||
if (in_array($pos, $validpos) && $this->showad)
|
||||
return $this->adrow[$pos];
|
||||
else return "";
|
||||
}
|
||||
}
|
||||
?>
|
||||
189
classes/class_attachment.php
Normal file
189
classes/class_attachment.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
class ATTACHMENT{
|
||||
var $userid;
|
||||
var $class;
|
||||
var $countlimit;
|
||||
var $countsofar=0;
|
||||
var $sizelimit;
|
||||
var $allowedext = array();
|
||||
|
||||
function __construct($userid) {
|
||||
$this->userid = $userid;
|
||||
$this->set_class();
|
||||
$this->set_count_so_far();
|
||||
$this->set_count_limit();
|
||||
$this->set_size_limit();
|
||||
$this->set_allowed_ext();
|
||||
}
|
||||
|
||||
function enable_attachment()
|
||||
{
|
||||
global $enableattach_attachment;
|
||||
if ($enableattach_attachment == 'yes')
|
||||
return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
function set_class()
|
||||
{
|
||||
$userid = $this->userid;
|
||||
$row = get_user_row($userid);
|
||||
$this->class = $row['class'];
|
||||
}
|
||||
|
||||
function set_count_so_far()
|
||||
{
|
||||
$userid = $this->userid;
|
||||
$now = date("Y-m-d H:i:s", TIMENOW-86400);
|
||||
$countsofar = get_row_count("attachments", "WHERE userid=".sqlesc($userid)." AND added > ".sqlesc($now));
|
||||
$this->countsofar = $countsofar;
|
||||
}
|
||||
|
||||
function get_count_so_far()
|
||||
{
|
||||
return $this->countsofar;
|
||||
}
|
||||
|
||||
function get_count_limit_class($class)
|
||||
{
|
||||
global $classone_attachment, $classtwo_attachment, $classthree_attachment, $classfour_attachment,$countone_attachment, $counttwo_attachment, $countthree_attachment, $countfour_attachment;
|
||||
if ($class >= $classfour_attachment && $countfour_attachment)
|
||||
return $countfour_attachment;
|
||||
elseif ($class >= $classthree_attachment && $countthree_attachment)
|
||||
return $countthree_attachment;
|
||||
elseif ($class >= $classtwo_attachment && $counttwo_attachment)
|
||||
return $counttwo_attachment;
|
||||
elseif ($class >= $classone_attachment && $countone_attachment)
|
||||
return $countone_attachment;
|
||||
}
|
||||
|
||||
function set_count_limit()
|
||||
{
|
||||
$class = $this->class;
|
||||
$countlimit = $this->get_count_limit_class($class);
|
||||
$this->countlimit = $countlimit;
|
||||
}
|
||||
|
||||
function get_count_limit()
|
||||
{
|
||||
return $this->countlimit;
|
||||
}
|
||||
|
||||
function get_count_left()
|
||||
{
|
||||
$left = $this->countlimit - $this->countsofar;
|
||||
return $left;
|
||||
}
|
||||
|
||||
function get_size_limit_class($class)
|
||||
{
|
||||
global $classone_attachment, $classtwo_attachment, $classthree_attachment, $classfour_attachment,$sizeone_attachment, $sizetwo_attachment, $sizethree_attachment, $sizefour_attachment;
|
||||
if ($class >= $classfour_attachment && $sizefour_attachment)
|
||||
return $sizefour_attachment;
|
||||
elseif ($class >= $classthree_attachment && $sizethree_attachment)
|
||||
return $sizethree_attachment;
|
||||
elseif ($class >= $classtwo_attachment && $sizetwo_attachment)
|
||||
return $sizetwo_attachment;
|
||||
elseif ($class >= $classone_attachment && $sizeone_attachment)
|
||||
return $sizeone_attachment;
|
||||
}
|
||||
|
||||
function set_size_limit()
|
||||
{
|
||||
$class = $this->class;
|
||||
$sizelimit = $this->get_size_limit_class($class);
|
||||
$this->sizelimit = $sizelimit;
|
||||
}
|
||||
|
||||
function get_size_limit_kb()
|
||||
{
|
||||
return $this->sizelimit;
|
||||
}
|
||||
|
||||
function get_size_limit_byte()
|
||||
{
|
||||
return $this->sizelimit * 1024;
|
||||
}
|
||||
|
||||
function get_allowed_ext_class($class)
|
||||
{
|
||||
global $classone_attachment, $classtwo_attachment, $classthree_attachment, $classfour_attachment,$extone_attachment, $exttwo_attachment, $extthree_attachment, $extfour_attachment;
|
||||
$allowedext = array();
|
||||
if ($class >= $classone_attachment){
|
||||
$temprow = $this->extract_allowed_ext($extone_attachment);
|
||||
if (count($temprow)){
|
||||
foreach ($temprow as $temp){
|
||||
$allowedext[] = $temp;
|
||||
}
|
||||
}
|
||||
if ($class >= $classtwo_attachment){
|
||||
$temprow = $this->extract_allowed_ext($exttwo_attachment);
|
||||
if (count($temprow)){
|
||||
foreach ($temprow as $temp){
|
||||
$allowedext[] = $temp;
|
||||
}
|
||||
}
|
||||
if ($class >= $classthree_attachment){
|
||||
$temprow = $this->extract_allowed_ext($extthree_attachment);
|
||||
if (count($temprow)){
|
||||
foreach ($temprow as $temp){
|
||||
$allowedext[] = $temp;
|
||||
}
|
||||
}
|
||||
if ($class >= $classfour_attachment){
|
||||
$temprow = $this->extract_allowed_ext($extfour_attachment);
|
||||
if (count($temprow)){
|
||||
foreach ($temprow as $temp){
|
||||
$allowedext[] = $temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $allowedext;
|
||||
}
|
||||
|
||||
function set_allowed_ext()
|
||||
{
|
||||
$class = $this->class;
|
||||
$allowedext = $this->get_allowed_ext_class($class);
|
||||
$this->allowedext = $allowedext;
|
||||
}
|
||||
|
||||
function get_allowed_ext()
|
||||
{
|
||||
return $this->allowedext;
|
||||
}
|
||||
|
||||
function extract_allowed_ext($string)
|
||||
{
|
||||
$string = rtrim(trim($string), ",");
|
||||
$exts = explode(",", $string);
|
||||
$extrow = array();
|
||||
foreach ($exts as $ext){
|
||||
$extrow[] = trim($ext);
|
||||
}
|
||||
return $extrow;
|
||||
}
|
||||
|
||||
function is_gif_ani($filename) {
|
||||
if(!($fh = @fopen($filename, 'rb')))
|
||||
return false;
|
||||
$count = 0;
|
||||
//an animated gif contains multiple "frames", with each frame having a
|
||||
//header made up of:
|
||||
// * a static 4-byte sequence (\x00\x21\xF9\x04)
|
||||
// * 4 variable bytes
|
||||
// * a static 2-byte sequence (\x00\x2C)
|
||||
|
||||
// We read through the file til we reach the end of the file, or we've found
|
||||
// at least 2 frame headers
|
||||
while(!feof($fh) && $count < 2){
|
||||
$chunk = fread($fh, 1024 * 100); //read 100kb at a time
|
||||
$count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00\x2C#s', $chunk, $matches);
|
||||
}
|
||||
return $count > 1;
|
||||
}
|
||||
}
|
||||
?>
|
||||
261
classes/class_cache.php
Normal file
261
classes/class_cache.php
Normal file
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
//Caching class (Based on file From ProjectGazelle)
|
||||
|
||||
class CACHE extends Memcache{
|
||||
var $isEnabled;
|
||||
var $clearCache = 0;
|
||||
var $language = 'en';
|
||||
var $Page = array();
|
||||
var $Row = 1;
|
||||
var $Part = 0;
|
||||
var $MemKey = "";
|
||||
var $Duration = 0;
|
||||
var $cacheReadTimes = 0;
|
||||
var $cacheWriteTimes = 0;
|
||||
var $keyHits = array();
|
||||
var $languageFolderArray = array();
|
||||
|
||||
function __construct($host = 'localhost', $port = 11211) {
|
||||
$success = $this->connect($host, $port); // Connect to memcache
|
||||
if ($success) {
|
||||
$this->isEnabled = 1;
|
||||
} else {
|
||||
$this->isEnabled = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function getIsEnabled() {
|
||||
return $this->isEnabled;
|
||||
}
|
||||
|
||||
function setClearCache($isEnabled) {
|
||||
$this->clearCache = $isEnabled;
|
||||
}
|
||||
|
||||
function getLanguageFolderArray() {
|
||||
return $this->languageFolderArray;
|
||||
}
|
||||
|
||||
function setLanguageFolderArray($languageFolderArray) {
|
||||
$this->languageFolderArray = $languageFolderArray;
|
||||
}
|
||||
|
||||
function getClearCache() {
|
||||
return $this->clearCache;
|
||||
}
|
||||
|
||||
function setLanguage($language) {
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
function getLanguage() {
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
function new_page($MemKey = '', $Duration = 3600, $Lang = true) {
|
||||
if ($Lang) {
|
||||
$language = $this->getLanguage();
|
||||
$this->MemKey = $language."_".$MemKey;
|
||||
} else {
|
||||
$this->MemKey = $MemKey;
|
||||
}
|
||||
$this->Duration = $Duration;
|
||||
$this->Row = 1;
|
||||
$this->Part = 0;
|
||||
$this->Page = array();
|
||||
}
|
||||
|
||||
function set_key(){
|
||||
|
||||
}
|
||||
|
||||
//---------- Adding functions ----------//
|
||||
|
||||
function add_row(){
|
||||
$this->Part = 0;
|
||||
$this->Page[$this->Row] = array();
|
||||
}
|
||||
|
||||
function end_row(){
|
||||
$this->Row++;
|
||||
}
|
||||
|
||||
function add_part(){
|
||||
ob_start();
|
||||
}
|
||||
|
||||
function end_part(){
|
||||
$this->Page[$this->Row][$this->Part]=ob_get_clean();
|
||||
$this->Part++;
|
||||
}
|
||||
|
||||
// Shorthand for:
|
||||
// add_row();
|
||||
// add_part();
|
||||
// You should only use this function if the row is only going to have one part in it (convention),
|
||||
// although it will theoretically work with multiple parts.
|
||||
function add_whole_row(){
|
||||
$this->Part = 0;
|
||||
$this->Page[$this->Row] = array();
|
||||
ob_start();
|
||||
}
|
||||
|
||||
// Shorthand for:
|
||||
// end_part();
|
||||
// end_row();
|
||||
// You should only use this function if the row is only going to have one part in it (convention),
|
||||
// although it will theoretically work with multiple parts.
|
||||
function end_whole_row(){
|
||||
$this->Page[$this->Row][$this->Part]=ob_get_clean();
|
||||
$this->Row++;
|
||||
}
|
||||
|
||||
// Set a variable that will only be availabe when the system is on its row
|
||||
// This variable is stored in the same way as pages, so don't use an integer for the $Key.
|
||||
function set_row_value($Key, $Value){
|
||||
$this->Page[$this->Row][$Key] = $Value;
|
||||
}
|
||||
|
||||
// Set a variable that will always be available, no matter what row the system is on.
|
||||
// This variable is stored in the same way as rows, so don't use an integer for the $Key.
|
||||
function set_constant_value($Key, $Value){
|
||||
$this->Page[$Key] = $Value;
|
||||
}
|
||||
|
||||
// Inserts a 'false' value into a row, which breaks out of while loops.
|
||||
// This is not necessary if the end of $this->Page is also the end of the while loop.
|
||||
function break_loop(){
|
||||
if(count($this->Page)>0){
|
||||
$this->Page[$this->Row] = FALSE;
|
||||
$this->Row++;
|
||||
}
|
||||
}
|
||||
|
||||
//---------- Locking functions ----------//
|
||||
|
||||
// These functions 'lock' a key.
|
||||
// Users cannot proceed until it is unlocked.
|
||||
|
||||
function lock($Key){
|
||||
$this->cache_value('lock_'.$Key, 'true', 3600);
|
||||
}
|
||||
|
||||
function unlock($Key) {
|
||||
$this->delete('lock_'.$Key);
|
||||
}
|
||||
|
||||
//---------- Caching functions ----------//
|
||||
|
||||
// Cache $this->Page and resets $this->Row and $this->Part
|
||||
function cache_page(){
|
||||
$this->cache_value($this->MemKey,$this->Page, $this->Duration);
|
||||
$this->Row = 0;
|
||||
$this->Part = 0;
|
||||
}
|
||||
|
||||
// Exact same as cache_page, but does not store the page in cache
|
||||
// This is so that we can use classes that normally cache values in
|
||||
// situations where caching is not required
|
||||
function setup_page(){
|
||||
$this->Row = 0;
|
||||
$this->Part = 0;
|
||||
}
|
||||
|
||||
// Wrapper for Memcache::set, with the zlib option removed and default duration of 1 hour
|
||||
function cache_value($Key, $Value, $Duration = 3600){
|
||||
$this->set($Key,$Value, 0, $Duration);
|
||||
$this->cacheWriteTimes++;
|
||||
$this->keyHits['write'][$Key] = !$this->keyHits['write'][$Key] ? 1 : $this->keyHits['write'][$Key]+1;
|
||||
}
|
||||
|
||||
//---------- Getting functions ----------//
|
||||
|
||||
// Returns the next row in the page
|
||||
// If there's only one part in the row, return that part.
|
||||
function next_row(){
|
||||
$this->Row++;
|
||||
$this->Part = 0;
|
||||
if($this->Page[$this->Row] == false){
|
||||
return false;
|
||||
}
|
||||
elseif(count($this->Page[$this->Row]) == 1){
|
||||
return $this->Page[$this->Row][0];
|
||||
}
|
||||
else {
|
||||
return $this->Page[$this->Row];
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the next part in the row
|
||||
function next_part(){
|
||||
$Return = $this->Page[$this->Row][$this->Part];
|
||||
$this->Part++;
|
||||
return $Return;
|
||||
}
|
||||
|
||||
// Returns a 'row value' (a variable that changes for each row - see above).
|
||||
function get_row_value($Key){
|
||||
return $this->Page[$this->Row][$Key];
|
||||
}
|
||||
|
||||
// Returns a 'constant value' (a variable that doesn't change with the rows - see above)
|
||||
function get_constant_value($Key){
|
||||
return $this->Page[$Key];
|
||||
}
|
||||
|
||||
// If a cached version of the page exists, set $this->Page to it and return true.
|
||||
// Otherwise, return false.
|
||||
function get_page(){
|
||||
$Result = $this->get_value($this->MemKey);
|
||||
if($Result){
|
||||
$this->Row = 0;
|
||||
$this->Part = 0;
|
||||
$this->Page = $Result;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Wrapper for Memcache::get. Why? Because wrappers are cool.
|
||||
function get_value($Key) {
|
||||
if($this->getClearCache()){
|
||||
$this->delete_value($Key);
|
||||
return false;
|
||||
}
|
||||
// If we've locked it
|
||||
// Xia Zuojie: we disable the following lock feature 'cause we don't need it and it doubles the time to fetch a value from a key
|
||||
/*while($Lock = $this->get('lock_'.$Key)){
|
||||
sleep(2);
|
||||
}*/
|
||||
|
||||
$Return = $this->get($Key);
|
||||
$this->cacheReadTimes++;
|
||||
$this->keyHits['read'][$Key] = !$this->keyHits['read'][$Key] ? 1 : $this->keyHits['read'][$Key]+1;
|
||||
return $Return;
|
||||
}
|
||||
|
||||
// Wrapper for Memcache::delete. For a reason, see above.
|
||||
function delete_value($Key, $AllLang = false){
|
||||
if ($AllLang){
|
||||
$langfolder_array = $this->getLanguageFolderArray();
|
||||
foreach($langfolder_array as $lf)
|
||||
$this->delete($lf."_".$Key);
|
||||
}
|
||||
else {
|
||||
$this->delete($Key);
|
||||
}
|
||||
}
|
||||
|
||||
function getCacheReadTimes() {
|
||||
return $this->cacheReadTimes;
|
||||
}
|
||||
|
||||
function getCacheWriteTimes() {
|
||||
return $this->cacheWriteTimes;
|
||||
}
|
||||
|
||||
function getKeyHits ($type='read') {
|
||||
return (array)$this->keyHits[$type];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user