| 1 |  |  | <?php namespace XoopsModules\Newbb; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * NewBB 5.0x,  the forum module for XOOPS project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright      XOOPS Project (https://xoops.org) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license        GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @author         Taiwen Jiang (phppp or D.J.) <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @since          4.00 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @package        module::newbb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Xmf\IPAddress; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use XoopsModules\Newbb; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | include_once __DIR__ . '/../include/functions.config.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * Class OnlineHandler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | class OnlineHandler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public $db; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public $forum_id; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     public $forumObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public $topic_id; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public $user_ids = []; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * OnlineHandler constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @param \XoopsDatabase $db | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     public function __construct(\XoopsDatabase $db) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->db = $db; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param null|Newbb\Forum $forum | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @param null|Topic  $forumtopic | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public function init($forum = null, $forumtopic = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 46 |  | View Code Duplication |         if (is_object($forum)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $this->forum_id    = $forum->getVar('forum_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             $this->forumObject = $forum; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $this->forum_id    = (int)$forum; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $this->forumObject = $forum; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 53 |  | View Code Duplication |         if (is_object($forumtopic)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             $this->topic_id = $forumtopic->getVar('topic_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             if (empty($this->forum_id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 $this->forum_id = $forumtopic->getVar('forum_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             $this->topic_id = (int)$forumtopic; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $this->update(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function update() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         global $xoopsModule; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         mt_srand((double)microtime() * 1000000); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         // set gc probabillity to 10% for now.. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         if (mt_rand(1, 100) < 60) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             $this->gc(150); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         if (is_object($GLOBALS['xoopsUser'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             $uid   = $GLOBALS['xoopsUser']->getVar('uid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             $uname = $GLOBALS['xoopsUser']->getVar('uname'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             $name  = $GLOBALS['xoopsUser']->getVar('name'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             $uid   = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             $uname = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             $name  = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $xoops_onlineHandler = xoops_getHandler('online'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $xoopsupdate         = $xoops_onlineHandler->write($uid, $uname, time(), $xoopsModule->getVar('mid'), \Xmf\IPAddress::fromRequest()->asReadable()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         if (!$xoopsupdate) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             //xoops_error("newbb online upate error"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $uname = (empty($GLOBALS['xoopsModuleConfig']['show_realname']) || empty($name)) ? $uname : $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $this->write($uid, $uname, time(), $this->forum_id, IPAddress::fromRequest()->asReadable(), $this->topic_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @param $xoopsTpl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     public function render(\Smarty $xoopsTpl) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         include_once __DIR__ . '/../include/functions.render.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         include_once __DIR__ . '/../include/functions.user.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $criteria = null; | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 102 |  | View Code Duplication |         if ($this->topic_id) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             $criteria = new \Criteria('online_topic', $this->topic_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         } elseif ($this->forum_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             $criteria = new \Criteria('online_forum', $this->forum_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $users     = $this->getAll($criteria); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $num_total = count($users); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $num_user     = 0; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $users_id     = []; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         $users_online = []; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 113 |  | View Code Duplication |         for ($i = 0; $i < $num_total; ++$i) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             if (empty($users[$i]['online_uid'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             $users_id[]                             = $users[$i]['online_uid']; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             $users_online[$users[$i]['online_uid']] = [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                 'link'  => XOOPS_URL . '/userinfo.php?uid=' . $users[$i]['online_uid'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                 'uname' => $users[$i]['online_uname'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             ++$num_user; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $num_anonymous           = $num_total - $num_user; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $online                  = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $online['image']         = newbbDisplayImage('whosonline'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         $online['num_total']     = $num_total; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $online['num_user']      = $num_user; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $online['num_anonymous'] = $num_anonymous; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $administrator_list      = newbbIsModuleAdministrators($users_id); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         $moderator_list          = []; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 132 |  | View Code Duplication |         if ($member_list = array_diff(array_keys($administrator_list), $users_id)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |             if (is_object($this->forumObject)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                 $moderator_list = $this->forumObject->getVar('forum_moderator'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                 $moderator_list = newbbIsForumModerators($member_list); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         foreach ($users_online as $uid => $user) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |             if (!empty($administrator_list[$uid])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |                 $user['level'] = 2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             } elseif (!empty($moderator_list[$uid])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                 $user['level'] = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                 $user['level'] = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             $online['users'][] = $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         $xoopsTpl->assign_by_ref('online', $online); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      * Deprecated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     public function showOnline() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         include_once __DIR__ . '/../include/functions.render.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         include_once __DIR__ . '/../include/functions.user.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         $criteria = null; | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 161 |  | View Code Duplication |         if ($this->topic_id) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             $criteria = new \Criteria('online_topic', $this->topic_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         } elseif ($this->forum_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |             $criteria = new \Criteria('online_forum', $this->forum_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         $users     = $this->getAll($criteria); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         $num_total = count($users); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         $num_user     = 0; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         $users_id     = []; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         $users_online = []; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 172 |  | View Code Duplication |         for ($i = 0; $i < $num_total; ++$i) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |             if (empty($users[$i]['online_uid'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |             $users_id[]                             = $users[$i]['online_uid']; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |             $users_online[$users[$i]['online_uid']] = [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |                 'link'  => XOOPS_URL . '/userinfo.php?uid=' . $users[$i]['online_uid'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |                 'uname' => $users[$i]['online_uname'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |             ++$num_user; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         $num_anonymous           = $num_total - $num_user; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         $online                  = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         $online['image']         = newbbDisplayImage('whosonline'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         $online['statistik']     = newbbDisplayImage('statistik'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         $online['num_total']     = $num_total; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         $online['num_user']      = $num_user; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         $online['num_anonymous'] = $num_anonymous; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         $administrator_list      = newbbIsModuleAdministrators($users_id); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         $moderator_list          = []; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 192 |  | View Code Duplication |         if ($member_list = array_diff($users_id, array_keys($administrator_list))) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |             if (is_object($this->forumObject)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |                 $moderator_list = $this->forumObject->getVar('forum_moderator'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |                 $moderator_list = newbbIsForumModerators($member_list); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         foreach ($users_online as $uid => $user) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |             if (in_array($uid, $administrator_list)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |                 $user['level'] = 2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |             } elseif (in_array($uid, $moderator_list)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |                 $user['level'] = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |                 $user['level'] = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |             $online['users'][] = $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         return $online; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |      * Write online information to the database | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |      * @param  int    $uid      UID of the active user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |      * @param  string $uname    Username | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |      * @param         $time | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |      * @param  string $forum_id Current forum_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |      * @param  string $ip       User's IP adress | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |      * @param         $topic_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |      * @return bool   TRUE on success | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |      * @internal param string $timestamp | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |     public function write($uid, $uname, $time, $forum_id, $ip, $topic_id) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |         global $xoopsModule, $xoopsDB; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |         $uid = (int)$uid; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         if ($uid > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |             $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_uid=' . $uid; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |             $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_uid=' . $uid . " AND online_ip='" . $ip . "'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         list($count) = $this->db->fetchRow($this->db->queryF($sql)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |         if ($count > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |             $sql = 'UPDATE ' . $this->db->prefix('newbb_online') . " SET online_updated= '" . $time . "', online_forum = '" . $forum_id . "', online_topic = '" . $topic_id . "' WHERE online_uid = " . $uid; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |             if (0 == $uid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |                 $sql .= " AND online_ip='" . $ip . "'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |             $sql = sprintf('INSERT INTO %s (online_uid, online_uname, online_updated, online_ip, online_forum, online_topic) VALUES (%u, %s, %u, %s, %u, %u)', $this->db->prefix('newbb_online'), $uid, $this->db->quote($uname), $time, $this->db->quote($ip), $forum_id, $topic_id); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |         if (!$this->db->queryF($sql)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |             //xoops_error($this->db->error()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |         /** @var \XoopsOnlineHandler $xoops_onlineHandler */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         $xoops_onlineHandler = xoops_getHandler('online'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |         $xoopsOnlineTable    = $xoops_onlineHandler->table; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |         $sql = 'DELETE FROM ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |                . $this->db->prefix('newbb_online') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |                . ' WHERE' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |                . ' ( online_uid > 0 AND online_uid NOT IN ( SELECT online_uid FROM ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |                . $xoopsOnlineTable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |                . ' WHERE online_module =' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |                . $xoopsModule->getVar('mid') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |                . ' ) )' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |                . ' OR ( online_uid = 0 AND online_ip NOT IN ( SELECT online_ip FROM ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |                . $xoopsOnlineTable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |                . ' WHERE online_module =' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |                . $xoopsModule->getVar('mid') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |                . ' AND online_uid = 0 ) )'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |         if ($result = $this->db->queryF($sql)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |             //xoops_error($this->db->error()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |      * Garbage Collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |      * Delete all online information that has not been updated for a certain time | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |      * @param int $expire Expiration time in seconds | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |     public function gc($expire) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |         global $xoopsModule; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |         $sql = 'DELETE FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_updated < ' . (time() - (int)$expire); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |         $this->db->queryF($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |         $xoops_onlineHandler = xoops_getHandler('online'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |         $xoops_onlineHandler->gc($expire); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |      * Get an array of online information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |      * @param  \CriteriaElement $criteria {@link \CriteriaElement} | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |      * @return array           Array of associative arrays of online information | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 298 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 299 |  |  |     public function getAll(\CriteriaElement $criteria = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 300 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 301 |  |  |         $ret   = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 302 |  |  |         $limit = $start = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 303 |  |  |         $sql   = 'SELECT * FROM ' . $this->db->prefix('newbb_online'); | 
            
                                                                        
                            
            
                                    
            
            
                | 304 |  |  |         if (is_object($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { | 
            
                                                                        
                            
            
                                    
            
            
                | 305 |  |  |             $sql   .= ' ' . $criteria->renderWhere(); | 
            
                                                                        
                            
            
                                    
            
            
                | 306 |  |  |             $limit = $criteria->getLimit(); | 
            
                                                                        
                            
            
                                    
            
            
                | 307 |  |  |             $start = $criteria->getStart(); | 
            
                                                                        
                            
            
                                    
            
            
                | 308 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 309 |  |  |         $result = $this->db->query($sql, $limit, $start); | 
            
                                                                        
                            
            
                                    
            
            
                | 310 |  |  |         if (!$result) { | 
            
                                                                        
                            
            
                                    
            
            
                | 311 |  |  |             return $ret; | 
            
                                                                        
                            
            
                                    
            
            
                | 312 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 313 |  |  |         while ($myrow = $this->db->fetchArray($result)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 314 |  |  |             $ret[] = $myrow; | 
            
                                                                        
                            
            
                                    
            
            
                | 315 |  |  |             if ($myrow['online_uid'] > 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 316 |  |  |                 $this->user_ids[] = $myrow['online_uid']; | 
            
                                                                        
                            
            
                                    
            
            
                | 317 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 318 |  |  |             unset($myrow); | 
            
                                                                        
                            
            
                                    
            
            
                | 319 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 320 |  |  |         $this->user_ids = array_unique($this->user_ids); | 
            
                                                                        
                            
            
                                    
            
            
                | 321 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 322 |  |  |         return $ret; | 
            
                                                                        
                            
            
                                    
            
            
                | 323 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |      * @param $uids | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |     public function checkStatus($uids) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |         $online_users = []; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |         $ret          = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |         if (!empty($this->user_ids)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |             $online_users = $this->user_ids; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |             $sql = 'SELECT online_uid FROM ' . $this->db->prefix('newbb_online'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |             if (!empty($uids)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |                 $sql .= ' WHERE online_uid IN (' . implode(', ', array_map('intval', $uids)) . ')'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |             $result = $this->db->query($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |             if (!$result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |                 return $ret; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |             while (list($uid) = $this->db->fetchRow($result)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |                 $online_users[] = $uid; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |         foreach ($uids as $uid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |             if (in_array($uid, $online_users)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |                 $ret[$uid] = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |         return $ret; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |      * Count the number of online users | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |      * @param  \CriteriaElement $criteria {@link CriteriaElement} | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |     public function getCount(\CriteriaElement $criteria = null) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |         $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |         if (is_object($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |             $sql .= ' ' . $criteria->renderWhere(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |         if (!$result = $this->db->query($sql)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |         list($ret) = $this->db->fetchRow($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |         return $ret; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 377 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 378 |  |  |  | 
            
                        
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.