boss86 Posted January 1, 2010 Report Share Posted January 1, 2010 Kur vajad edit laj pievinotu so skriptu forumam? <?php /* IPB online users * Version: 2.0.3 * Last update: 03.06.2009 * * Author: * Emīls * [email protected] * www.stand-by.lv * * Docs: * ipb_online::__construct([ string $url [, string $prefix ]] ); // $url = forum url without index.php but ending slash, $prefix = database forum table prefix * ipb_online::config( string $key, string $value ); // configuration options: (boolean) location - shows what user is doing in forum, false by default; (boolean) last_click - shows time when user did last click, false by default; (boolean) group - shows user group title, true by default; (boolean) avatar - shows user avatar, true by default; (integer) offset - custom online offset in seconds * ipb_online::set_lang( array $data ); // language array * ipb_online::create_cache(f); // get data from database * ipb_online::list_online_members(root); // output online members list * ipb_online::list_board_data( ); // output overall online values and registered members count * * Usage: * Before you need defined mysql connection! * $online = new ipb_online(); * $online->config('avatar', false); * $online->set_lang($_IPB_LANG); * $online->create_cache(); * echo $online->list_online_members(); * echo $online->list_board_data(); * * TODO: <li class="board_members"><span>%s</span>: %d</li> * - avatar max width/height * - active topic title * - active forum title * - last registered member */ class ipb_online { static $prefix; static $url; private $cfg; private $cache; private $lang = array(); public $data; public function __construct($url = '/', $prefix = 'ibf_'){ self::$prefix = $prefix; self::$url = $url; $this->cfg = (object)array( 'location' => false, 'last_click' => false, 'group' => true, 'avatar' => true, 'offset' => 0 ); $this->data = (object)array( 'count' => (object)array( 'online' => (object)array( 'guests' => 0, 'members' => 0 ), 'registered' => 0 ), 'members' => array() ); $this->cache = (object)array( 'groups' => array(), 'avatars' => array() ); return $this; } public function config($key, $value){ $this->cfg->$key = $value; } public function set_lang($data){ if(!is_array($data)){ return false; } $this->lang = $data; } function __($key){ return (array_key_exists($key, $this->lang) && !empty($this->lang[$key])) ? $this->lang[$key] : sprintf('LX{%s}', $key); } public function create_cache(){ $offset = $this->cfg->offset > 0 ? " WHERE running_time>=".(time()-$this->cfg->offset) : ""; $sql = "SELECT member_name, member_id, running_time, location, member_group, location_1_type, location_1_id, location_2_type, location_2_id FROM `".self::$prefix."sessions`".$offset." ORDER BY running_time DESC"; $res = mysql_query($sql); if(mysql_num_rows($res)<1){ return false; } $groups = $avatars = $members = array(); $count = (object)array( 'members' => 0, 'guests' => 0 ); while($row = mysql_fetch_object($res)){ if(empty($row->member_id)){ ++$this->data->count->online->guests; continue; } if(!in_array($row->member_group, $groups)){ $groups[] = $row->member_group; } if(in_array($row->member_id, $avatars)){ continue; } ++$this->data->count->online->members; $avatars[] = $row->member_id; $this->data->members[] = (object)array( 'id' => $row->member_id, 'name' => $row->member_name, 'group_id' => $row->member_group, 'time' => $row->running_time, 'location' => array( 0 => $row->location, 1 => (object)array( 'type' => $row->location_1_type, 'id' => $row->location_1_id ), 2 => (object)array( 'type' => $row->location_2_type, 'id' => $row->location_2_id ) ) ); } if(!empty($groups)){ $this->get_groups($groups); } if(!empty($avatars) && $this->cfg->avatar==true){ $this->get_avatars($avatars); } $this->data->count->registered = mysql_fetch_object(mysql_query("SELECT COUNT(*) AS c FROM `".self::$prefix."members`"))->c; return $this; } private function get_groups($groups){ $sql = "SELECT g_id, g_title, prefix, suffix FROM `".self::$prefix."groups` WHERE g_id IN (".implode(",", $groups).")"; $res = mysql_query($sql); while($row = mysql_fetch_object($res)){ $this->cache->groups[$row->g_id] = $row; } } private function get_avatars($members){ $sql = "SELECT id, avatar_location, avatar_size, avatar_type FROM `".self::$prefix."member_extra` WHERE id IN (".implode(",", $members).")"; $res = mysql_query($sql); while($row = mysql_fetch_object($res)){ $this->cache->avatars[$row->id] = $row; } } private function format_time($time){ $now = time(); if($now<=$time){ return $this->__('less_than_second'); } $minute = 60; $hour = $minute*60; $diff = $now-$time; $minutes = floor($diff/$minute); if($minutes<1){ return '<span class="time">'.$this->__('before').' '.$diff.' '.$this->__('second'.(substr($diff, -1)==1 ? '' : 's')).'</span>'; } $hours = floor($diff/$hour); if($hours<1){ return '<span class="time">'.$this->__('before').' '.$minutes.' '.$this->__('minute'.(substr($minutes, -1)==1 ? '' : 's')).'</span>'; } return '<span class="time">'.$this->__('before').' '.$hours.' '.$this->__('hour'.(substr($hours, -1)==1 ? '' : 's')).'</span>'; } private function format_location($l){ if($l[0] == 'st'){ return sprintf('<a class="location" href="%s?showtopic=%d">%s</a>', self::$url, $l[1]->id, $this->__('viewing_topic')); } if($l[0] == 'sf'){ return sprintf('<a class="location" href="%s?showforum=%d">%s</a>', self::$url, $l[2]->id, $this->__('viewing_forum')); } if(substr($l[0], 0, 3) == 'idx'){ return sprintf('<a class="location" href="%s">%s</a>', self::$url, $this->__('viewing_board_index')); } if($l[0] == 'post'){ return sprintf('<a class="location" href="%s?act=post&do=reply_post&f=%d&t=%d">%s</a>', self::$url, $l[2]->id, $l[1]->id, $this->__('posting')); } if(substr($l[0], 0, 3) == 'Msg'){ return sprintf('<a class="location" href="%s?act=Msg">%s</a>', self::$url, $this->__('messaging')); } if(substr($l[0], 0, 6) == 'UserCP'){ return sprintf('<a class="location" href="%s?act=UserCP">%s</a>', self::$url, $this->__('usercp')); } if(substr($l[0], 0, 6) == 'Search'){ return sprintf('<a class="location" href="%s?act=Search">%s</a>', self::$url, $this->__('searching')); } if(substr($l[0], 0, 7) == 'profile'){ return '<span class="location">'.$this->__('viewing_profile').'</span>'; } if(substr($l[0], 0, 7) == 'Members'){ return sprintf('<a class="location" href="%s?act=Members">%s</a>', self::$url, $this->__('viewing_members')); } if(substr($l[0], 0, 8) == 'calendar'){ return sprintf('<a class="location" href="%s?act=calendar">%s</a>', self::$url, $this->__('viewing_calendar')); } if(substr($l[0], 0, 4) == 'Help'){ return sprintf('<a class="location" href="%s?act=Help">%s</a>', self::$url, $this->__('viewing_help')); } } function format_avatar($id){ $avatar = $this->cache->avatars[$id]; if(empty($avatar->avatar_location)){ return ''; } list($width, $height) = explode("x", $avatar->avatar_size); if($avatar->avatar_type == 'local'){ return sprintf('<img src="%sstyle_avatars/%s" alt="" width="%d" height="%d" />', self::$url, $avatar->avatar_location, $width, $height); } if($avatar->avatar_type == 'upload'){ return sprintf('<img src="%suploads/%s" alt="" width="%d" height="%d" />', self::$url, $avatar->avatar_location, $width, $height); } if($avatar->avatar_type == 'url'){ return sprintf('<img src="%s" alt="" width="%d" height="%d" />', $avatar->avatar_location, $width, $height); } } public function list_online_members(){ $r = '<ul class="online_members">'; foreach($this->data->members as $member){ $group = $this->cache->groups[$member->group_id]; $r.= sprintf( '<li class="%s">%s<a href="%s?showuser=%d">%s%s%s</a>%s%s%s</li>', preg_replace("/[^a-z0-9\-_]/", "", strtolower($group->g_title)), $this->cfg->avatar == true ? $this->format_avatar($member->id) : '', self::$url, $member->id, $this->cfg->group == true ? $group->prefix : '', $member->name, $this->cfg->group == true ? $group->suffix : '', $this->cfg->group == false ? '<br />'.$group->prefix.$group->g_title.$group->suffix : '', $this->cfg->last_click == true ? '<br />'.$this->format_time($member->time) : '', $this->cfg->location == true ? '<br />'.$this->format_location($member->location) : '' ); } $r.= '</ul>'; return $r; } public function list_board_data(){ return sprintf(' <ul class="board_data"> <li class="online_total"><span>%s</span>: %d</li> <li class="online_users"><span>%s</span>: %d</li> <li class="online_guests"><span>%s</span>: %d</li> </ul> ', $this->__('online_total'), $this->data->count->online->members+$this->data->count->online->guests, $this->__('online_users'), $this->data->count->online->members, $this->__('online_guests'), $this->data->count->online->guests, $this->__('board_members'), $this->data->count->registered); } } $_IPB_LANG = array( 'less_than_second' => 'mazāk kā pirms sekundes', 'before' => 'pirms', 'second' => 'sekunde', 'seconds' => 'sekundes', 'minute' => 'minūtes', 'minutes' => 'minūtēm', 'hour' => 'stundas', 'hours' => 'stundām', 'viewing_topic' => 'lasa topiku', 'viewing_forum' => 'skatās forumu', 'viewing_board_index' => 'foruma sākumlapā', 'posting' => 'raksta atbildi', 'messaging' => 'Ienira vēstulēs', 'usercp' => 'labo profilu', 'searching' => 'meklē', 'viewing_profile' => 'skatās lietotāju', 'viewing_members' => 'meklē lietotājus', 'viewing_calendar' => 'skatās kalendāru', 'viewing_help' => 'lasa palīdzību', 'online_total' => 'Kopā online', 'online_users' => 'Lietotāji online', 'online_guests' => 'Viesi online', 'board_members' => 'Kopā reģistrēti lietotāji' ); $_IPB_LANG_EN = array( 'less_than_second' => 'less than second ago', 'before' => '', 'second' => 'seconds ago', 'seconds' => 'seconds ago', 'minute' => 'minutes ago', 'minutes' => 'minutes ago', 'hour' => 'hours ago', 'hours' => 'hours ago', 'viewing_topic' => 'reading topic', 'viewing_forum' => 'viewing forum', 'viewing_board_index' => 'at board index', 'posting' => 'posting reply', 'messaging' => 'messaging', 'usercp' => 'at control panel', 'searching' => 'searching', 'viewing_profile' => 'viewing profile', 'viewing_members' => 'browsing members', 'viewing_calendar' => 'at calendar', 'viewing_help' => 'reading help', 'online_total' => 'Online', 'online_users' => 'Members online', 'online_guests' => 'Guests online', 'board_members' => 'Registered members' ); ?> Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now