| 1 |  |  | <?php namespace Xoopsmodules\instruction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Xmf\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Xoopsmodules\instruction\common; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | require_once __DIR__ . '/common/VersionChecks.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | require_once __DIR__ . '/common/ServerStats.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | require_once __DIR__ . '/common/FilesManagement.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | require_once __DIR__ . '/../include/common.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * Class Utility | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | class Utility | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     use common\VersionChecks; //checkVerXoops, checkVerPhp Traits | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     use common\ServerStats; // getServerStats Trait | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     use common\FilesManagement; // Files Management Trait | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     // Права | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @param string $permtype | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public static function getItemIds($permtype = 'instruction_view') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         //global $xoopsUser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         static $permissions = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         // Если есть в статике | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         if (is_array($permissions) && array_key_exists($permtype, $permissions)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             return $permissions[$permtype]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         // Находим из базы | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $moduleHandler          = xoops_getHandler('module'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $instrModule            = $moduleHandler->getByDirname('instruction'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $groups                 = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $gpermHandler           = xoops_getHandler('groupperm'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $categories             = $gpermHandler->getItemIds($permtype, $groups, $instrModule->getVar('mid')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $permissions[$permtype] = $categories; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         return $categories; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     // Редактор | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param        $caption | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @param        $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @return bool|\XoopsFormEditor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public static function getWysiwygForm($caption, $name, $value = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $editor                   = false; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $editor_configs           = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $editor_configs['name']   = $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $editor_configs['value']  = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $editor_configs['rows']   = 35; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $editor_configs['cols']   = 60; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $editor_configs['width']  = '100%'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $editor_configs['height'] = '350px'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $editor_configs['editor'] = strtolower(xoops_getModuleOption('form_options', 'instruction')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $editor = new \XoopsFormEditor($caption, $name, $editor_configs); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         return $editor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     // Получение значения переменной, переданной через GET или POST запрос | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @param        $global | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @param        $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @param string $default | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @param string $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @return int|string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |     public static function cleanVars(&$global, $key, $default = '', $type = 'int') | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |         switch ($type) { | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |             case 'string': | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |                 $ret = isset($global[$key]) ? $global[$key] : $default; | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |                 break; | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |             case 'int': | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |             default: | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |                 $ret = isset($global[$key]) ? (int)$global[$key] : (int)$default; | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |                 break; | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |         if (false === $ret) { | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |             return $default; | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |         return $ret; | 
            
                                                        
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 95 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |  | 
            
                        
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.