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

Last change on this file since 3655 was 3609, checked in by patdenice, 15 years ago

Convert all php and tpl files in Unix format for my plugins.

File size: 5.2 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'] = realpath($this->get_template($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  /* Return template for user template/theme*/
172  function get_template($file)
173  {
174    global $user, $template;
175
176    $dir = STUFFS_PATH . 'template/';
177    $theme_file = $dir.$user['template'].'/'.$user['theme'].'/'.$file;
178    $template_file = $dir.$user['template'].'/'.$file;
179
180    if (file_exists($theme_file))
181    {
182      return $theme_file;
183    }
184    elseif (file_exists($template_file))
185    {
186      return $template_file;
187    }
188    else
189    {
190      return $dir.$file;
191    }
192  }
193}
194
195?>
Note: See TracBrowser for help on using the repository browser.