1+ <?PHP
2+ function addon_channelinfo_toplist (&$ addons_config ,$ ts3 ,$ mysqlcon ,$ cfg ,$ dbname ,$ lang ,&$ db_cache ) {
3+ $ sqlexec = '' ;
4+ $ nowtime = time ();
5+
6+ $ smarty = new Smarty ();
7+
8+ $ smarty ->setTemplateDir ($ cfg ['logs_path ' ].'smarty/templates ' );
9+ $ smarty ->setCompileDir ($ cfg ['logs_path ' ].'smarty/templates_c ' );
10+ $ smarty ->setCacheDir ($ cfg ['logs_path ' ].'smarty/cache ' );
11+ $ smarty ->setConfigDir ($ cfg ['logs_path ' ].'smarty/configs ' );
12+
13+ if (isset ($ addons_config ['channelinfo_toplist_active ' ]['value ' ]) && $ addons_config ['channelinfo_toplist_active ' ]['value ' ] == '1 ' ) {
14+ if ($ addons_config ['channelinfo_toplist_lastupdate ' ]['value ' ] < ($ nowtime - $ addons_config ['channelinfo_toplist_delay ' ]['value ' ])) {
15+
16+ switch ($ addons_config ['channelinfo_toplist_modus ' ]['value ' ]) {
17+ case 1 : $ filter = "ORDER BY (`count_week`-`idle_week`) " ; break ;
18+ case 2 : $ filter = "ORDER BY `count_week` " ; break ;
19+ case 3 : $ filter = "ORDER BY (`count_month`-`idle_month`) " ; break ;
20+ case 4 : $ filter = "ORDER BY `count_month` " ; break ;
21+ case 5 : $ filter = "ORDER BY (`count`-`idle`) " ; break ;
22+ case 6 : $ filter = "ORDER BY `count` " ; break ;
23+ default : $ filter = "ORDER BY (`count_week`-`idle_week`) " ;
24+ }
25+
26+ $ notinuuid = '' ;
27+ if ($ cfg ['rankup_excepted_unique_client_id_list ' ] != NULL ) {
28+ foreach ($ cfg ['rankup_excepted_unique_client_id_list ' ] as $ uuid => $ value ) {
29+ $ notinuuid .= "' " .$ uuid ."', " ;
30+ }
31+ $ notinuuid = substr ($ notinuuid , 0 , -1 );
32+ } else {
33+ $ notinuuid = "'0' " ;
34+ }
35+
36+ $ notingroup = '' ;
37+ $ andnotgroup = '' ;
38+ if ($ cfg ['rankup_excepted_group_id_list ' ] != NULL ) {
39+ foreach ($ cfg ['rankup_excepted_group_id_list ' ] as $ group => $ value ) {
40+ $ notingroup .= "' " .$ group ."', " ;
41+ $ andnotgroup .= " AND `user`.`cldgroup` NOT LIKE (' " .$ group .",%') AND `user`.`cldgroup` NOT LIKE ('%, " .$ group .",%') AND `user`.`cldgroup` NOT LIKE ('%, " .$ group ."') " ;
42+ }
43+ $ notingroup = substr ($ notingroup , 0 , -1 );
44+ } else {
45+ $ notingroup = '0 ' ;
46+ }
47+
48+ $ filter = " AND `user`.`uuid` NOT IN ( $ notinuuid) AND `user`.`cldgroup` NOT IN ( $ notingroup) $ andnotgroup " .$ filter ;
49+ #enter_logfile($cfg,2,'SQL: '."SELECT * FROM `$dbname`.`stats_user` INNER JOIN `$dbname`.`user` ON `user`.`uuid` = `stats_user`.`uuid` WHERE `removed`='0' {$filter} DESC LIMIT 10");
50+
51+ if (($ userdata = $ mysqlcon ->query ("SELECT * FROM ` $ dbname`.`stats_user` INNER JOIN ` $ dbname`.`user` ON `user`.`uuid` = `stats_user`.`uuid` WHERE `removed`='0' {$ filter } DESC LIMIT 10 " )->fetchAll (PDO ::FETCH_ASSOC )) === false ) {
52+ enter_logfile ($ cfg ,2 ,'addon_channelinfo1: ' .print_r ($ mysqlcon ->errorInfo (), true ));
53+ }
54+
55+ $ smarty ->assign ('LAST_UPDATE_TIME ' ,(DateTime::createFromFormat ('U.u ' , number_format (microtime (true ), 6 , '. ' , '' ))->setTimeZone (new DateTimeZone ($ cfg ['logs_timezone ' ]))->format ("Y-m-d H:i:s " )));
56+
57+ for ($ nr = 0 ; $ nr < 10 ; $ nr ++) {
58+ $ smarty ->assign ('CLIENT_UNIQUE_IDENTIFIER_ ' .($ nr + 1 ),$ userdata [$ nr ]['uuid ' ]);
59+ $ smarty ->assign ('CLIENT_DATABASE_ID_ ' .($ nr + 1 ),$ userdata [$ nr ]['cldbid ' ]);
60+ $ smarty ->assign ('CLIENT_NICKNAME_ ' .($ nr + 1 ),$ userdata [$ nr ]['name ' ]);
61+
62+ if ($ userdata [$ nr ]['firstcon ' ] == 0 ) {
63+ $ smarty ->assign ('CLIENT_CREATED_ ' .($ nr + 1 ),$ lang ['unknown ' ]);
64+ } else {
65+ $ smarty ->assign ('CLIENT_CREATED_ ' .($ nr + 1 ),date ('Y-m-d H:i:s ' ,$ userdata [$ nr ]['firstcon ' ]));
66+ }
67+ $ smarty ->assign ('CLIENT_LAST_SEEN_ ' .($ nr + 1 ),date ('Y-m-d H:i:s ' ,$ userdata [$ nr ]['lastseen ' ]));
68+ $ smarty ->assign ('CLIENT_TOTAL_CONNECTIONS_ ' .($ nr + 1 ),$ userdata [$ nr ]['total_connections ' ]);
69+ $ smarty ->assign ('CLIENT_DESCRIPTION_ ' .($ nr + 1 ),$ userdata [$ nr ]['client_description ' ]);
70+ $ smarty ->assign ('CLIENT_CURRENT_CHANNEL_ID_ ' .($ nr + 1 ),$ userdata [$ nr ]['cid ' ]);
71+ if (isset ($ db_cache ['channel ' ][$ userdata [$ nr ]['cid ' ]]['channel_name ' ])) {
72+ $ smarty ->assign ('CLIENT_CURRENT_CHANNEL_NAME_ ' .($ nr + 1 ),substr ($ db_cache ['channel ' ][$ userdata [$ nr ]['cid ' ]]['channel_name ' ],1 ,-1 ));
73+ } else {
74+ $ smarty ->assign ('CLIENT_CURRENT_CHANNEL_NAME_ ' .($ nr + 1 ),$ lang ['unknown ' ]);
75+ }
76+ $ smarty ->assign ('CLIENT_VERSION_ ' .($ nr + 1 ),$ userdata [$ nr ]['version ' ]);
77+ $ smarty ->assign ('CLIENT_PLATFORM_ ' .($ nr + 1 ),$ userdata [$ nr ]['platform ' ]);
78+ $ smarty ->assign ('CLIENT_COUNTRY_ ' .($ nr + 1 ),$ userdata [$ nr ]['nation ' ]);
79+
80+ if ($ userdata [$ nr ]['grpsince ' ] == 0 ) {
81+ $ smarty ->assign ('CLIENT_LAST_RANKUP_TIME_ ' .($ nr + 1 ),$ lang ['unknown ' ]);
82+ } else {
83+ $ smarty ->assign ('CLIENT_LAST_RANKUP_TIME_ ' .($ nr + 1 ),date ('Y-m-d H:i:s ' ,$ userdata [$ nr ]['grpsince ' ]));
84+ }
85+ $ smarty ->assign ('CLIENT_RANK_POSITION_ ' .($ nr + 1 ),$ userdata [$ nr ]['rank ' ]);
86+ if ($ userdata [$ nr ]['online ' ] == 1 ) {
87+ $ smarty ->assign ('CLIENT_ONLINE_STATUS_ ' .($ nr + 1 ),$ lang ['stix0024 ' ]);
88+ } else {
89+ $ smarty ->assign ('CLIENT_ONLINE_STATUS_ ' .($ nr + 1 ),$ lang ['stix0025 ' ]);
90+ }
91+
92+ $ smarty ->assign ('CLIENT_NEXT_RANKUP_TIME_ ' .($ nr + 1 ),$ userdata [$ nr ]['nextup ' ]);
93+
94+ $ smarty ->assign ('CLIENT_CURRENT_RANK_GROUP_ID_ ' .($ nr + 1 ),$ userdata [$ nr ]['grpid ' ]);
95+ if (isset ($ db_cache ['groups ' ][$ userdata [$ nr ]['grpid ' ]]['sgidname ' ])) {
96+ $ smarty ->assign ('CLIENT_CURRENT_RANK_GROUP_NAME_ ' .($ nr + 1 ),substr ($ db_cache ['groups ' ][$ userdata [$ nr ]['grpid ' ]]['sgidname ' ],1 ,-1 ));
97+ } else {
98+ $ smarty ->assign ('CLIENT_CURRENT_RANK_GROUP_NAME_ ' .($ nr + 1 ),'unknown_group ' );
99+ }
100+ if (isset ($ db_cache ['groups ' ][$ userdata [$ nr ]['grpid ' ]]['iconid ' ]) && isset ($ db_cache ['groups ' ][$ userdata [$ nr ]['grpid ' ]]['ext ' ])) {
101+ $ smarty ->assign ('CLIENT_CURRENT_RANK_GROUP_ICON_URL_ ' .($ nr + 1 ),'tsicons/ ' .$ db_cache ['groups ' ][$ userdata [$ nr ]['grpid ' ]]['iconid ' ].'. ' .$ db_cache ['groups ' ][$ userdata [$ nr ]['grpid ' ]]['ext ' ]);
102+ } else {
103+ $ smarty ->assign ('CLIENT_CURRENT_RANK_GROUP_ICON_URL_ ' .($ nr + 1 ),'file_not_found ' );
104+ }
105+ $ active_all = round ($ userdata [$ nr ]['count ' ]) - round ($ userdata [$ nr ]['idle ' ]);
106+ $ smarty ->assign ('CLIENT_ACTIVE_TIME_ALL_ ' .($ nr + 1 ),((new DateTime ("@0 " ))->diff (new DateTime ("@ " .$ active_all ))->format ($ cfg ['default_date_format ' ])));
107+ $ smarty ->assign ('CLIENT_ONLINE_TIME_ALL_ ' .($ nr + 1 ),((new DateTime ("@0 " ))->diff (new DateTime ("@ " .round ($ userdata [$ nr ]['count ' ])))->format ($ cfg ['default_date_format ' ])));
108+ $ smarty ->assign ('CLIENT_IDLE_TIME_ALL_ ' .($ nr + 1 ),((new DateTime ("@0 " ))->diff (new DateTime ("@ " .round ($ userdata [$ nr ]['idle ' ])))->format ($ cfg ['default_date_format ' ])));
109+ $ active_week = round ($ userdata [$ nr ]['count_week ' ]) - round ($ userdata [$ nr ]['idle_week ' ]);
110+ $ smarty ->assign ('CLIENT_ACTIVE_TIME_LAST_WEEK_ ' .($ nr + 1 ),((new DateTime ("@0 " ))->diff (new DateTime ("@ " .$ active_week ))->format ($ cfg ['default_date_format ' ])));
111+ $ smarty ->assign ('CLIENT_ONLINE_TIME_LAST_WEEK_ ' .($ nr + 1 ),((new DateTime ("@0 " ))->diff (new DateTime ("@ " .round ($ userdata [$ nr ]['count_week ' ])))->format ($ cfg ['default_date_format ' ])));
112+ $ smarty ->assign ('CLIENT_IDLE_TIME_LAST_WEEK_ ' .($ nr + 1 ),((new DateTime ("@0 " ))->diff (new DateTime ("@ " .round ($ userdata [$ nr ]['idle_week ' ])))->format ($ cfg ['default_date_format ' ])));
113+ $ active_month = round ($ userdata [$ nr ]['count_month ' ]) - round ($ userdata [$ nr ]['idle_month ' ]);
114+ $ smarty ->assign ('CLIENT_ACTIVE_TIME_LAST_MONTH_ ' .($ nr + 1 ),((new DateTime ("@0 " ))->diff (new DateTime ("@ " .$ active_month ))->format ($ cfg ['default_date_format ' ])));
115+ $ smarty ->assign ('CLIENT_ONLINE_TIME_LAST_MONTH_ ' .($ nr + 1 ),((new DateTime ("@0 " ))->diff (new DateTime ("@ " .round ($ userdata [$ nr ]['count_month ' ])))->format ($ cfg ['default_date_format ' ])));
116+ $ smarty ->assign ('CLIENT_IDLE_TIME_LAST_MONTH_ ' .($ nr + 1 ),((new DateTime ("@0 " ))->diff (new DateTime ("@ " .round ($ userdata [$ nr ]['idle_month ' ])))->format ($ cfg ['default_date_format ' ])));
117+ }
118+
119+ try {
120+ $ toplist_desc = $ smarty ->fetch ('string: ' .$ addons_config ['channelinfo_toplist_desc ' ]['value ' ]);
121+ if ($ addons_config ['channelinfo_toplist_lastdesc ' ]['value ' ] != $ toplist_desc ) {
122+ try {
123+ $ ts3 ->channelGetById ($ addons_config ['channelinfo_toplist_channelid ' ]['value ' ])->modify (array ('cid= ' .$ addons_config ['channelinfo_toplist_channelid ' ]['value ' ], 'channel_description= ' .$ toplist_desc ));
124+ $ addons_config ['channelinfo_toplist_lastdesc ' ]['value ' ] = $ toplist_desc ;
125+ $ addons_config ['channelinfo_toplist_lastupdate ' ]['value ' ] = $ nowtime ;
126+ $ toplist_desc = $ mysqlcon ->quote ($ toplist_desc , ENT_QUOTES );
127+ $ sqlexec .= "INSERT IGNORE INTO ` $ dbname`.`addons_config` (`param`,`value`) VALUES ('channelinfo_toplist_lastdesc', {$ toplist_desc }),('channelinfo_toplist_lastupdate',' {$ nowtime }') ON DUPLICATE KEY UPDATE `value`=VALUES(`value`); \n" ;
128+ enter_logfile ($ cfg ,5 ,' Addon: \'channelinfo_toplist \' writing new channelinfo toplist to channel description. ' );
129+ } catch (Exception $ e ) {
130+ enter_logfile ($ cfg ,2 ,'addon_channelinfo2: [ ' .$ e ->getCode ().']: ' .$ e ->getMessage ());
131+ }
132+ }
133+ } catch (Exception $ e ) {
134+ $ errmsg = str_replace ('" ' , '\'' , $ e ->getMessage ());
135+ $ addons_config ['channelinfo_toplist_lastupdate ' ]['value ' ] = $ nowtime ;
136+ $ sqlexec .= "INSERT IGNORE INTO ` $ dbname`.`addons_config` (`param`,`value`) VALUES ('channelinfo_toplist_lastupdate',' {$ nowtime }') ON DUPLICATE KEY UPDATE `value`=VALUES(`value`); \n" ;
137+ enter_logfile ($ cfg ,2 ,' Addon: \'channelinfo_toplist \'; There might be a syntax error in your \'channel description \', which is defined in the webinterface! Error message: [ ' .$ e ->getCode ().']: ' .$ errmsg );
138+ }
139+ }
140+ }
141+
142+ unset($ smarty );
143+ return $ sqlexec ;
144+ }
145+ ?>
0 commit comments