[3609] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 4 | |
---|
| 5 | class stuffs |
---|
| 6 | { |
---|
| 7 | var $user_groups = array(); |
---|
| 8 | var $modules = array(); |
---|
[9369] | 9 | var $blocks = array(); |
---|
| 10 | var $pos = 'begin'; |
---|
[9410] | 11 | var $prefixe = 'PLUGIN_INDEX_CONTENT_'; |
---|
[3609] | 12 | |
---|
| 13 | function stuffs() |
---|
| 14 | { |
---|
[9383] | 15 | global $page, $template; |
---|
| 16 | |
---|
| 17 | if ($page['stuffs_section'] == 'on_picture') |
---|
| 18 | { |
---|
[9410] | 19 | $this->prefixe = 'PLUGIN_PICTURE_'; |
---|
[9383] | 20 | $template->set_prefilter('header', array('stuffs', 'prefilter_picture_css')); |
---|
| 21 | pwgs_picture_special_sections(); |
---|
| 22 | } |
---|
| 23 | else |
---|
| 24 | { |
---|
| 25 | $template->set_prefilter( 'header', array('stuffs', 'prefilter_index_css') ); |
---|
| 26 | } |
---|
| 27 | |
---|
[3609] | 28 | $this->get_user_groups(); |
---|
| 29 | $this->get_modules(); |
---|
| 30 | $this->process_modules(); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | /* Retrieve user groups */ |
---|
| 34 | function get_user_groups() |
---|
| 35 | { |
---|
| 36 | global $user; |
---|
| 37 | |
---|
| 38 | $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';'; |
---|
| 39 | $result = pwg_query($query); |
---|
| 40 | while ($row = mysql_fetch_assoc($result)) |
---|
| 41 | { |
---|
| 42 | array_push($this->user_groups, $row['group_id']); |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | /* Retrieve modules from table */ |
---|
| 47 | function get_modules() |
---|
| 48 | { |
---|
| 49 | global $page, $user; |
---|
| 50 | |
---|
[9383] | 51 | if (!isset($page['stuffs_section'])) return; |
---|
| 52 | |
---|
[3609] | 53 | $query = ' |
---|
[9410] | 54 | SELECT DISTINCT id, name, path, datas, groups, show_title, id_line, width |
---|
[3609] | 55 | FROM ' . STUFFS_TABLE . ' |
---|
[9383] | 56 | LEFT JOIN ' . USER_GROUP_TABLE . ' |
---|
| 57 | ON user_id = '.$user['id'].' |
---|
| 58 | WHERE (users IS NULL OR users LIKE "%' . $user['status'] . '%") |
---|
| 59 | AND (groups IS NULL OR groups REGEXP CONCAT("(^|,)",group_id,"(,|$)")) |
---|
| 60 | AND level <= '.$user['level'].' |
---|
| 61 | AND '.$page['stuffs_section'].' = "true" |
---|
| 62 | ORDER BY pos ASC |
---|
| 63 | ;'; |
---|
[3609] | 64 | |
---|
| 65 | $result = pwg_query($query); |
---|
| 66 | |
---|
| 67 | while ($row = mysql_fetch_assoc($result)) |
---|
| 68 | { |
---|
| 69 | array_push($this->modules, $row); |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | /* Process modules */ |
---|
| 74 | function process_modules() |
---|
| 75 | { |
---|
[9369] | 76 | global $pwg_loaded_plugins; |
---|
| 77 | |
---|
[3609] | 78 | foreach ($this->modules as $module) |
---|
| 79 | { |
---|
[9369] | 80 | if ($module['name'] == 'MainBlock') |
---|
[7541] | 81 | { |
---|
[9369] | 82 | $this->pos = 'end'; |
---|
[7855] | 83 | if (!empty($module['datas']) |
---|
| 84 | and $datas = unserialize($module['datas']) |
---|
| 85 | and $datas['hide']) |
---|
[7541] | 86 | { |
---|
| 87 | add_event_handler('loc_end_index', 'hide_main_block'); |
---|
| 88 | } |
---|
[9369] | 89 | continue; |
---|
| 90 | } |
---|
[9410] | 91 | |
---|
| 92 | preg_match('#^'.preg_quote(PHPWG_PLUGINS_PATH).'([^/]*?)/#', $module['path'], $match); |
---|
| 93 | if (!isset($pwg_loaded_plugins[$match[1]])) |
---|
[7855] | 94 | { |
---|
[9369] | 95 | continue; |
---|
| 96 | } |
---|
[7541] | 97 | |
---|
[9369] | 98 | $datas = (!empty($module['datas']) ? unserialize($module['datas']) : false); |
---|
[3609] | 99 | $block = array(); |
---|
| 100 | |
---|
[9369] | 101 | include($module['path'].'main.inc.php'); |
---|
[3609] | 102 | |
---|
[9369] | 103 | if (!empty($block['TEMPLATE'])) |
---|
[3609] | 104 | { |
---|
[9369] | 105 | $block['ID'] = $module['id']; |
---|
| 106 | if ($module['show_title'] == 'true') |
---|
| 107 | { |
---|
| 108 | $block['TITLE'] = trigger_event('render_stuffs_name', $module['name']); |
---|
| 109 | } |
---|
| 110 | if (is_admin()) |
---|
| 111 | { |
---|
| 112 | $block['U_EDIT'] = PHPWG_ROOT_PATH.'admin.php?page=plugin&section='.STUFFS_DIR.'%2Fadmin%2Fadmin.php&tab=edit_module&edit='.$module['id'].'&redirect='.urlencode(urlencode($_SERVER['REQUEST_URI'])); |
---|
| 113 | } |
---|
| 114 | $this->set_tpl_block($block, $module); |
---|
[3609] | 115 | } |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | /* Set template blocks */ |
---|
[9369] | 119 | function set_tpl_block($block, $module) |
---|
| 120 | { |
---|
| 121 | if (!empty($module['id_line'])) |
---|
[3609] | 122 | { |
---|
| 123 | $block['id_line'] = $module['id_line']; |
---|
| 124 | $block['given_width'] = !empty($module['width']) ? $module['width'] : ''; |
---|
| 125 | |
---|
| 126 | if (!empty($this->blocks[$this->pos])) |
---|
| 127 | { |
---|
| 128 | $last = end($this->blocks[$this->pos]); |
---|
| 129 | $key = key($this->blocks[$this->pos]); |
---|
| 130 | $penul = prev($this->blocks[$this->pos]); |
---|
| 131 | |
---|
| 132 | if (isset($last['id_line']) and $last['id_line'] == $module['id_line']) |
---|
| 133 | { |
---|
| 134 | if (isset($penul['id_line']) and $penul['id_line'] == $module['id_line']) |
---|
| 135 | { |
---|
| 136 | $i = 3; |
---|
| 137 | !$block['given_width'] or $i--; |
---|
| 138 | !$last['given_width'] or $i--; |
---|
| 139 | !$penul['given_width'] or $i--; |
---|
| 140 | |
---|
| 141 | !$i or $default_width = intval((100 - $block['given_width'] - $last['given_width'] - $penul['given_width']) / $i); |
---|
| 142 | |
---|
| 143 | $penul['WIDTH'] = $penul['given_width'] ? $penul['given_width'] : $default_width; |
---|
| 144 | $block['WIDTH'] = $block['given_width'] ? $block['given_width'] : $default_width; |
---|
| 145 | |
---|
| 146 | $block['CLASS'] = 'right_block'; |
---|
| 147 | $block['new_line'] = false; |
---|
| 148 | $block['end_line'] = false; |
---|
| 149 | $last['end_line'] = true; |
---|
| 150 | $this->blocks[$this->pos][$key-1] = $penul; |
---|
| 151 | $this->blocks[$this->pos][$key] = $block; |
---|
| 152 | $this->blocks[$this->pos][] = $last; |
---|
| 153 | return; |
---|
| 154 | } |
---|
| 155 | else |
---|
| 156 | { |
---|
| 157 | if (empty($block['given_width']) and empty($last['given_width'])) |
---|
| 158 | { |
---|
| 159 | $last['WIDTH'] = 50; |
---|
| 160 | } |
---|
| 161 | elseif ($block['given_width']>0) |
---|
| 162 | { |
---|
| 163 | $last['WIDTH'] = 100 - $block['given_width']; |
---|
| 164 | } |
---|
| 165 | else |
---|
| 166 | { |
---|
| 167 | $last['WIDTH'] = $last['given_width']; |
---|
| 168 | } |
---|
| 169 | $block['CLASS'] = 'middle_block'; |
---|
| 170 | $last['CLASS'] = 'left_block'; |
---|
| 171 | $block['new_line'] = false; |
---|
| 172 | $block['end_line'] = true; |
---|
| 173 | $last['end_line'] = false; |
---|
| 174 | $this->blocks[$this->pos][$key] = $last; |
---|
| 175 | $this->blocks[$this->pos][] = $block; |
---|
| 176 | return; |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | $block['new_line'] = true; |
---|
| 183 | $block['end_line'] = true; |
---|
| 184 | $block['CLASS'] = 'middle_block'; |
---|
[9369] | 185 | $this->blocks[$this->pos][] = $block; |
---|
| 186 | } |
---|
[3609] | 187 | |
---|
[5727] | 188 | static function prefilter_index_css($source, &$smarty) |
---|
[3609] | 189 | { |
---|
[5727] | 190 | $css = array( |
---|
| 191 | '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}plugins/PWG_Stuffs/theme/stuffs_index.css">' |
---|
| 192 | ); |
---|
[3609] | 193 | |
---|
[5727] | 194 | foreach ($smarty->get_template_vars('themes') as $theme) |
---|
[3609] | 195 | { |
---|
[7336] | 196 | if (file_exists(PHPWG_THEMES_PATH.$theme['id'].'/stuffs_index.css')) |
---|
[5727] | 197 | { |
---|
| 198 | array_push($css, '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}themes/'.$theme['id'].'/stuffs_index.css">'); |
---|
| 199 | } |
---|
[3609] | 200 | } |
---|
[5727] | 201 | |
---|
| 202 | $source = str_replace("\n</head>", "\n".implode( "\n", $css )."\n</head>", $source); |
---|
| 203 | |
---|
| 204 | return $source; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | static function prefilter_picture_css($source, &$smarty) |
---|
| 208 | { |
---|
| 209 | $css = array( |
---|
| 210 | '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}plugins/PWG_Stuffs/theme/stuffs_picture.css">' |
---|
| 211 | ); |
---|
| 212 | |
---|
| 213 | foreach ($smarty->get_template_vars('themes') as $theme) |
---|
[3609] | 214 | { |
---|
[5727] | 215 | if (file_exists(PHPWG_THEMES_DIR.$theme['id'].'/stuffs_picture.css')) |
---|
| 216 | { |
---|
| 217 | array_push($css, '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}themes/'.$theme['id'].'/stuffs_picture.css">'); |
---|
| 218 | } |
---|
[3609] | 219 | } |
---|
[5727] | 220 | |
---|
| 221 | if (!empty($css)) |
---|
[3609] | 222 | { |
---|
[5727] | 223 | $source = str_replace("\n</head>", "\n".implode( "\n", $css )."\n</head>", $source); |
---|
[3609] | 224 | } |
---|
[5727] | 225 | |
---|
| 226 | return $source; |
---|
[3609] | 227 | } |
---|
| 228 | } |
---|
| 229 | |
---|
[7402] | 230 | ?> |
---|