| 1 |  |  | <?php | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | // ------------------------------------------------------------------------ // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | // XOOPS - PHP Content Management System                      // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | // Copyright (c) 2000-2016 XOOPS.org                           // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | // <http://xoops.org/>                             // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | // ------------------------------------------------------------------------ // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | // This program is free software; you can redistribute it and/or modify     // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | // it under the terms of the GNU General Public License as published by     // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | // the Free Software Foundation; either version 2 of the License, or        // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | // (at your option) any later version.                                      // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | // // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | // You may not change or alter any portion of this comment or credits       // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | // of supporting developers from this source code or any supporting         // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | // source code which is considered copyrighted (c) material of the          // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | // original comment or credit authors.                                      // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | // // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | // This program is distributed in the hope that it will be useful,          // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of           // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | // GNU General Public License for more details.                             // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | // // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | // You should have received a copy of the GNU General Public License        // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | // along with this program; if not, write to the Free Software              // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | // ------------------------------------------------------------------------ // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | // Author: phppp (D.J., [email protected])                                  // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | //  URL: http://xoops.org                                                    // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | // Project: Article Project                                                 // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | // ------------------------------------------------------------------------ // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | include_once $GLOBALS['xoops']->path('class/xoopstree.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  * Class Newbbtree | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | class NewbbTree extends XoopsTree | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     public $prefix    = '  '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public $increment = '  '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     public $postArray = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @param        $table_name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @param string $id_name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * @param string $pid_name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function __construct($table_name, $id_name = 'post_id', $pid_name = 'pid') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         parent::__construct($table_name, $id_name, $pid_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @param string $val | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     public function setPrefix($val = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->prefix    = $val; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->increment = $val; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @param        $sel_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @param string $order | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public function getAllPostArray($sel_id, $order = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->postArray = $this->getAllChild($sel_id, $order); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @param $postArray | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |     public function setPostArray($postArray) | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |         $this->postArray = $postArray; | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     // returns an array of first child objects for a given id($sel_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @param         $postTree_array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @param  int    $pid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @param  string $prefix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     public function getPostTree(&$postTree_array, $pid = 0, $prefix = '  ') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         if (!is_array($postTree_array)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             $postTree_array = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $newPostArray = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $prefix       .= $this->increment; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         foreach ($this->postArray as $post) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             if ($post->getVar('pid') == $pid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                 $postTree_array[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                     'prefix'      => $prefix, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                     'icon'        => $post->getVar('icon'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                     'post_time'   => $post->getVar('post_time'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                     'post_id'     => $post->getVar('post_id'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                     'forum_id'    => $post->getVar('forum_id'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                     'subject'     => $post->getVar('subject'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                     'poster_name' => $post->getVar('poster_name'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                     'uid'         => $post->getVar('uid') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                 ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                 $this->getPostTree($postTree_array, $post->getVar('post_id'), $prefix); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |                 $newPostArray[] = $post; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $this->postArray = $newPostArray; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         unset($newPostArray); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 118 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 119 |  |  |  | 
            
                        
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.