source: extensions/PWG_Stuffs/include/class.inc.php @ 6422

Last change on this file since 6422 was 6230, checked in by patdenice, 14 years ago

Corrections

File size: 5.9 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5class stuffs
6{
7  var $user_groups = array();
8  var $modules = array();
9        var $blocks = array();
10        var $pos = 'begin';
11
12  function stuffs()
13  {
14    $this->get_user_groups();
15    $this->get_modules();
16    $this->process_modules();
17  }
18
19  /* Retrieve user groups  */
20  function get_user_groups()
21  {
22    global $user;
23
24    $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';';
25    $result = pwg_query($query);
26    while ($row = mysql_fetch_assoc($result))
27    {
28      array_push($this->user_groups, $row['group_id']);
29    }
30  }
31
32  /* Retrieve modules from table */
33  function get_modules()
34  {
35    global $page, $user;
36
37    $query = '
38SELECT id, name, type, datas, groups, show_title, id_line, width
39FROM ' . STUFFS_TABLE . '
40WHERE users LIKE "%' . $user['status'] . '%"
41';
42
43    $script = script_basename();
44    if ($script == 'index')
45    {
46      $query .= isset($page['category']) ?
47        'AND on_cats = "true"' :
48        'AND on_home = "true"' ;
49    }
50    elseif ($script == 'picture')
51    {
52      $query .= 'AND on_picture = "true"';
53    }
54    else return;
55
56    $query .= '
57ORDER BY pos ASC;';
58
59    $result = pwg_query($query);
60
61    while ($row = mysql_fetch_assoc($result))
62    {
63      array_push($this->modules, $row);
64    }
65  }
66
67  /* Process modules */
68  function process_modules()
69  {
70    foreach ($this->modules as $module)
71    {
72      if ($module['type'] == 'MainBlock')
73      {
74                $this->pos = 'end';
75                continue;
76        }
77        if (!empty($module['groups']))
78      {
79                $authorized_groups = explode(',', $module['groups']);
80                if (array_intersect($this->user_groups, $authorized_groups) == array()) continue;
81        }
82
83        $datas = (!empty($module['datas']) ? unserialize($module['datas']) : false);
84      $block = array();
85
86        if ((include(STUFFS_PATH . 'modules/' . $module['type'] . '/main.inc.php')) === false) continue;
87
88      $block['ID'] = $module['id'];
89      if ($module['show_title'] == 'true')
90      {
91        $block['TITLE'] = trigger_event('render_stuffs_name', $module['name']);
92      }
93      if (is_admin())
94      {
95        $block['U_EDIT'] = PHPWG_ROOT_PATH.'admin.php?page=plugin&amp;section='.STUFFS_DIR.'%2Fadmin%2Fadd_module.php&amp;type='.$module['type'].'&amp;edit='.$module['id'];
96      }
97      $block['TEMPLATE'] = 'stuffs_'.strtolower($module['type']).'.tpl';
98        $this->set_tpl_block($block, $module);
99    }
100  }
101  /* Set template blocks  */
102        function set_tpl_block($block, $module)
103        {
104                if (!empty($module['id_line']))
105    {
106      $block['id_line'] = $module['id_line'];
107      $block['given_width'] = !empty($module['width']) ? $module['width'] : '';
108
109      if (!empty($this->blocks[$this->pos]))
110      {
111        $last = end($this->blocks[$this->pos]);
112        $key = key($this->blocks[$this->pos]);
113        $penul = prev($this->blocks[$this->pos]);
114
115        if (isset($last['id_line']) and $last['id_line'] == $module['id_line'])
116        {
117          if (isset($penul['id_line']) and $penul['id_line'] == $module['id_line'])
118          {
119            $i = 3;
120            !$block['given_width'] or $i--;
121            !$last['given_width'] or $i--;
122            !$penul['given_width'] or $i--;
123
124            !$i or $default_width = intval((100 - $block['given_width'] - $last['given_width'] - $penul['given_width']) / $i);
125
126            $penul['WIDTH'] = $penul['given_width'] ? $penul['given_width'] : $default_width;
127            $block['WIDTH'] = $block['given_width'] ? $block['given_width'] : $default_width;
128
129            $block['CLASS'] = 'right_block';
130            $block['new_line'] = false;
131            $block['end_line'] = false;
132            $last['end_line'] = true;
133            $this->blocks[$this->pos][$key-1] = $penul;
134            $this->blocks[$this->pos][$key] = $block;
135            $this->blocks[$this->pos][] = $last;
136            return;
137          }
138          else
139          {
140            if (empty($block['given_width']) and empty($last['given_width']))
141            {
142              $last['WIDTH'] = 50;
143            }
144            elseif ($block['given_width']>0)
145            {
146              $last['WIDTH'] = 100 - $block['given_width'];
147            }
148            else
149            {
150              $last['WIDTH'] = $last['given_width'];
151            }
152            $block['CLASS'] = 'middle_block';
153            $last['CLASS'] = 'left_block';
154            $block['new_line'] = false;
155            $block['end_line'] = true;
156            $last['end_line'] = false;
157            $this->blocks[$this->pos][$key] = $last;
158            $this->blocks[$this->pos][] = $block;
159            return;
160          }
161        }
162      }
163    }
164
165    $block['new_line'] = true;
166    $block['end_line'] = true;
167    $block['CLASS'] = 'middle_block';
168        $this->blocks[$this->pos][] = $block;
169        }
170
171  static function prefilter_index_css($source, &$smarty)
172  {
173    $css = array(
174      '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}plugins/PWG_Stuffs/theme/stuffs_index.css">'
175    );
176
177    foreach ($smarty->get_template_vars('themes') as $theme)
178    {
179      if (file_exists(PHPWG_THEMES_DIR.$theme['id'].'/stuffs_index.css'))
180      {
181        array_push($css, '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}themes/'.$theme['id'].'/stuffs_index.css">');
182      }
183    }
184
185    $source = str_replace("\n</head>", "\n".implode( "\n", $css )."\n</head>", $source);
186
187    return $source;
188  }
189
190  static function prefilter_picture_css($source, &$smarty)
191  {
192    $css = array(
193      '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}plugins/PWG_Stuffs/theme/stuffs_picture.css">'
194    );
195
196    foreach ($smarty->get_template_vars('themes') as $theme)
197    {
198      if (file_exists(PHPWG_THEMES_DIR.$theme['id'].'/stuffs_picture.css'))
199      {
200        array_push($css, '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}themes/'.$theme['id'].'/stuffs_picture.css">');
201      }
202    }
203
204    if (!empty($css))
205    {
206      $source = str_replace("\n</head>", "\n".implode( "\n", $css )."\n</head>", $source);
207    }
208
209    return $source;
210  }
211}
212
213?>
Note: See TracBrowser for help on using the repository browser.