path = $path; } function _secure($nick) { return ereg_replace('[^a-zA-Z0-9_]', '', $nick); } function login($nick, $password) { $nick = $this->_secure($nick); if(!file_exists('users/'.$nick)) return 'NO_USER'; if(!$this->exists($nick)) return 'NICK_NOT_FOUND'; if(!$this->checkPassword($nick, $password)) return 'BAD_PASSWORD'; @session_start(); $_SESSION['is_logged'] = $nick; return true; } function is_logged() { @session_start(); if(!empty($_SESSION['is_logged'])) return true; return false; } function current_user() { @session_start(); if(empty($_SESSION['is_logged'])) return false; return $_SESSION['is_logged']; } function logout() { @session_start(); $_SESSION['is_logged'] = false; return true; } function exists($nick) { $nick = $this->_secure($nick); if(!file_exists($this->path.$nick.'.accounts')) return false; return true; } function checkPassword($nick, $password) { $nick = $this->_secure($nick); $fp = @fopen($this->path.$nick.'.accounts', 'r'); if(!$fp) return false; $pass = fread($fp, 32); fclose($fp); if($pass != md5($password)) return false; return true; } function create($nick) { $nick = $this->_secure($nick); if(file_exists('users/'.$nick)) return true; if(!$this->exists($nick)) return false; if(!mkdir('users/'.$nick, 0777)) return false; if(!mkdir('users/'.$nick.'/buddies', 0777) || !mkdir('users/'.$nick.'/emoticons', 0777)) { @rmdir('users/'.$nick.'/buddies'); @rmdir('users/'.$nick.'/emoticons'); @rmdir('users/'.$nick); return false; } return true; } function getMyPic() { $pic = 'users/'.$this->current_user().'/myself.png'; if(!file_exists($pic)) return false; return $pic.'?t='.time(); } function uploadPic($file) { if(empty($file) || empty($file['tmp_name']) || empty($file['size'])) return false; if(!move_uploaded_file($file['tmp_name'], 'users/'.$this->current_user().'/myself.new')) return false; $img = getimagesize('users/'.$this->current_user().'/myself.new'); if(empty($img)) return false; if($img[0] != '96' || $img[1] != '96' || $img[2] != '3') { @unlink('users/'.$this->current_user().'/myself.new'); return 'BAD_FORMAT'; } if(file_exists('users/'.$this->current_user().'/myself.png')) @unlink('users/'.$this->current_user().'/myself.png'); rename('users/'.$this->current_user().'/myself.new', 'users/'.$this->current_user().'/myself.png'); return true; } function _deleteBuddyIcon($file) { @unlink('users/'.$this->current_user().'/buddies/'.$file); } function deleteBuddy($buddy) { $buddies = $this->_getBuddies(); foreach($buddies as $file) { list($nick) = explode(".", $file); if($nick == $buddy) $this->_deleteBuddyIcon($file); } return true; } function _getBuddies() { if(!empty($this->buddies)) { return $this->buddies; } $path = 'users/'.$this->current_user().'/buddies/'; $buddies = array(); $handle = opendir($path); while($file = readdir($handle)) { if(substr($file, 0, 1) == '.') continue; // Deleting invalid things if any if(filesize($path.$file) < 1000 || substr($file,-4) != ".png") { $this->_deleteBuddyIcon($file); continue; } list($content) = file($path.$file); if(!ereg('PNG', $content)) { $this->_deleteBuddyIcon($file); continue; } $time = filemtime($path.$file); $buddies[$time] = $file; } closedir($handle); krsort($buddies); $this->buddies = $buddies; return $buddies; } function getBuddies() { $buddies = $this->_getBuddies(); $out = array(); foreach($buddies as $icon) { list($nick) = explode(".", $icon); if(!empty($out[$nick])) { if(!$this->keep_old) @unlink('users/'.$this->current_user().'/buddies/'.$icon); continue; } $out[$nick] = $icon; } natcasesort($out); return $out; } function getEmoticons() { } } // Speed and ugly template class class Template { var $tpl = false; var $vars = array(); function assign($key, $value) { $this->vars[$key] = $value; } function open($tpl) { $tpl = file($tpl); $tpl = implode('', $tpl); $this->tpl = $tpl; } function loop($name, $array) { preg_match('/\{loop '.$name.'\}(.*)\{/loop\}/', $this->tpl, $match); $out = ''; foreach($array as $key=>$value) { $str = $match[1]; foreach($value as $item=>$value2) { $str = str_replace('item.'.$item, $value2, $str); } $out.= $str; } $this->tpl = str_replace($match[0], $out, $this->tpl); } function display() { extract($this->vars); eval("echo <<tpl."\n\nEOF;\n"); } } $bitlbee = new Bitlbee(!empty($path) ? $path : false); define('JTPL_PATH', dirname(__FILE__) . '/jtpl/'); define('JTPL_CACHE_PATH', realpath(JTPL_PATH.'temp/') . '/'); define('JTPL_PLUGIN_PATH', realpath(JTPL_PATH.'plugins/') . '/'); define('JTPL_LOCALES_PATH', realpath(JTPL_PATH.'locales/') . '/'); define('JTPL_TEMPLATES_PATH', 'templates/'); $GLOBALS['jTplConfig'] = array( 'tplpluginsPathList'=> array( 'common' => array(JTPL_PLUGIN_PATH . 'common/'), 'html' => array(JTPL_PLUGIN_PATH . 'html/') ), 'compilation_force' => true, 'lang'=>'fr', 'localesGetter' => 'getLocales' ); include(JTPL_PATH . 'jTpl.class.php'); function getLocales($locale) { return $locale; } $tpl = new jTpl(); ?>