source: extensions/Flash_Gallery/include/class.inc.php @ 3531

Last change on this file since 3531 was 3531, checked in by tiico, 15 years ago

First revision (for testing)
Only in French (translation to be done)

File size: 8.3 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5
6class flashgal
7{
8  var $user_groups = array();
9//  var $modules = array();
10  var $module = null;
11  var $blocks = array();
12  var $pos = 'begin';
13
14  function flashgal($catid = null, $home = null, $permalinkcat = null)
15  {
16 
17    $this->get_user_groups();
18    $this->get_modules($catid, $home);
19    $this->process_modules($catid, $home, $permalinkcat);
20  }
21
22  /* Retrieve user groups  */
23  function get_user_groups()
24  {
25    global $user;
26
27    $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';';
28    $result = pwg_query($query);
29    while ($row = mysql_fetch_assoc($result))
30    {
31      array_push($this->user_groups, $row['group_id']);
32    }
33  }
34
35  /* Retrieve module */
36  function get_module()
37  {
38                $module = $this->module; 
39                return $module;
40  }
41 
42 
43  /* Retrieve modules from table */
44  function get_modules($catid = null, $home = null)
45  {
46
47    global $page, $user;
48        $module_found = false;
49
50       
51    $query = '
52SELECT *
53FROM ' . FLASHGAL_TABLE . '
54WHERE users LIKE "%' . $user['status'] . '%"
55';
56
57// FAire un test par rapport aux variables $catid et $home
58/*
59    $script = script_basename();
60    if ($script == 'index')
61    {
62      $query .= isset($page['category']) ?
63        'AND on_cats = "true"' :
64        'AND on_home = "true"' ;
65    }
66*/
67if ($home)
68        $query .= 'AND on_home = "true"' ;
69elseif ($catid)
70        $query .= 'AND on_cats = "true"' ;
71
72    $query .= '
73        ORDER BY pos ASC;';
74
75    $result = pwg_query($query);
76    while ($row = mysql_fetch_assoc($result))
77    {
78                // seulement si aucun module est trouvé.
79                if( !$module_found)
80                {
81                        // Besoin de positionner le module par rapport au 'Mainblock'
82                    if ($row['type'] == 'MainBlock')
83                    {
84                        $this->pos = 'end';
85                        continue;
86                    }
87               
88                        // categories actives pour le module
89                        $row['cats'] = (!empty($row['cats']) ? unserialize($row['cats']) : false);
90/*
91                        if( (empty($page['category']) and $row['on_home'] = "true")     // Home
92                                || ( (isset($page['category'])) and $row['on_cats'] = "true" and (in_array($page['category']['id'], $row['cats'])) )    // category and in module conf
93                          )
94*/                     
95                        if ( ($home and $row['on_home'] = "true")       // Home
96                                || ( $catid and $row['on_cats'] = "true" and (in_array($catid, $row['cats'])) ) // category and in module conf
97                           )
98                        {
99                                $this->module = $row;
100                                // seul le premier correspondant est pris en compte
101//                              break;
102                                $module_found = true;
103                        }
104                }
105        }
106}
107
108  /* Process modules */
109  function process_modules($catid = null, $home = null, $permalinkcat = null)
110  {
111//    foreach ($this->modules as $module)
112        if ($this->module != null)
113    {
114                $module = $this->module;
115            if ($module['type'] == 'MainBlock')
116            {
117                $this->pos = 'end';
118                continue;
119            }
120
121                if (!empty($module['groups']))
122                {
123                $authorized_groups = explode(',', $module['groups']);
124                if (array_intersect($this->user_groups, $authorized_groups) == array()) continue;
125        }
126
127        $datas = (!empty($module['datas']) ? unserialize($module['datas']) : false);
128                $block = array();
129
130
131      $block['ID'] = $module['id'];
132      if ($module['show_title'] == 'true')
133      {
134        $block['TITLE'] = trigger_event('render_flashgal_name', $module['name']);
135      }
136      if (is_admin())
137      {
138        $block['U_EDIT'] = PHPWG_ROOT_PATH.'admin.php?page=plugin&amp;section='.FLASHGAL_DIR.'%2Fadmin%2Fadd_module.php&amp;type='.$module['type'].'&amp;edit='.$module['id'];
139      }
140         
141      $block['TEMPLATE'] = $this->get_template($module['type'].'.tpl', $module['type']);
142          $block['TEMPLATE'] = realpath($block['TEMPLATE']);
143         
144          include(FLASHGAL_PATH . 'modules/' . $module['type']. '/module.inc.php');
145         
146          $block['FLASHNAME'] = FLASHGAL_PATH . 'modules/' . $module['type']. '/'.$module_data['FlashName'];   
147          $block['FLASHVARXML'] = $module_data['FlashvarXML'];
148
149          set_make_full_url();
150//        $catid = empty($page['category']['permalink']) ? $page['category']['id'] : $page['category']['permalink'];
151//        echo "page['category']['id']=".$catid;
152//        $block['XMLFEED'] = embellish_url(get_root_url().FLASHGAL_PATH.'generate-xml.php?/'.(isset($page['category']) ? 'category'.(isset($catid) ? $catid : '') : 'categories'));
153       
154//        $block['XMLFEED'] = embellish_url(get_root_url().FLASHGAL_PATH.'generate-xml.php%3F/'.(isset($page['category']) ? 'category'.(isset($catid) ? $catid : '') : 'categories'));
155          $block['XMLFEED'] = embellish_url(get_root_url().FLASHGAL_PATH.'generate-xml.php?/'.(isset($permalinkcat) ? 'category/'.$permalinkcat : (isset($catid) ? 'category/' . $catid  : 'categories' )));
156//        $block['XMLFEED'] = embellish_url(FLASHGAL_PATH.'generate-xml.php?/'.(isset($permalinkcat) ? 'category/'.$permalinkcat : (isset($catid) ? 'category/' . $catid  : 'categories' )));
157
158
159        if (isset($module_data['GET_Mode']) && $module_data['GET_Mode'])
160                $block['XMLFEED'] = embellish_url(get_root_url().FLASHGAL_PATH.'generate-xml.php?'
161                                                        .(isset($permalinkcat) ? 'permalink='.$permalinkcat : (isset($catid) ? 'catid=' . $catid  : 'home' )));
162
163
164          unset_make_full_url();
165
166          $block['HEIGHT']= $module['height'];
167          $block['TRANSPARENT'] = ($module['transparent'] == 'true' ? true : false);
168          $block['FULLSCREEN'] = $module['fullscreen'];
169          $block['BGCOLOR'] = $module['bgcolor'];
170
171          if ((include(FLASHGAL_PATH . 'modules/' . $module['type'] . '/main.inc.php')) === false) continue;
172         
173          $this->set_tpl_block($block, $module);
174
175        }
176  }
177
178  /* Set template blocks  */
179        function set_tpl_block($block, $module)
180        {
181        // TIICO : A supprimer car id_line est toujours vide, pas d'utilite de cette partie par rapport a PWG Stuff
182        if (!empty($module['id_line']))
183    {
184      $block['id_line'] = $module['id_line'];
185      $block['given_width'] = '';
186
187      if (!empty($this->blocks[$this->pos]))
188      {
189        $last = end($this->blocks[$this->pos]);
190        $key = key($this->blocks[$this->pos]);
191        $penul = prev($this->blocks[$this->pos]);
192
193        if (isset($last['id_line']) and $last['id_line'] == $module['id_line'])
194        {
195          if (isset($penul['id_line']) and $penul['id_line'] == $module['id_line'])
196          {
197            $i = 3;
198            !$block['given_width'] or $i--;
199            !$last['given_width'] or $i--;
200            !$penul['given_width'] or $i--;
201
202            !$i or $default_width = intval((100 - $block['given_width'] - $last['given_width'] - $penul['given_width']) / $i);
203
204            $penul['WIDTH'] = $penul['given_width'] ? $penul['given_width'] : $default_width;
205            $block['WIDTH'] = $block['given_width'] ? $block['given_width'] : $default_width;
206
207            $block['CLASS'] = 'right_block';
208            $block['new_line'] = false;
209            $block['end_line'] = false;
210            $last['end_line'] = true;
211            $this->blocks[$this->pos][$key-1] = $penul;
212            $this->blocks[$this->pos][$key] = $block;
213            $this->blocks[$this->pos][] = $last;
214            return;
215          }
216          else
217          {
218            if (empty($block['given_width']) and empty($last['given_width']))
219            {
220              $last['WIDTH'] = 50;
221            }
222            elseif ($block['given_width']>0)
223            {
224              $last['WIDTH'] = 100 - $block['given_width'];
225            }
226            else
227            {
228              $last['WIDTH'] = $last['given_width'];
229            }
230            $block['CLASS'] = 'middle_block';
231            $last['CLASS'] = 'left_block';
232            $block['new_line'] = false;
233            $block['end_line'] = true;
234            $last['end_line'] = false;
235            $this->blocks[$this->pos][$key] = $last;
236            $this->blocks[$this->pos][] = $block;
237            return;
238          }
239        }
240      }
241    }
242
243    $block['new_line'] = true;
244    $block['end_line'] = true;
245    $block['CLASS'] = 'middle_block';
246        $this->blocks[$this->pos][] = $block;
247        }
248 
249  /* Return template for user template/theme*/
250  function get_template($file, $modulename = null)
251  {
252    global $user, $template;
253
254
255    if (isset($modulename))
256                $dir = FLASHGAL_PATH . 'modules/'.$modulename .'/';
257        else
258                $dir = FLASHGAL_PATH . 'template/';
259
260//                      echo "dir=".$dir.$file;
261    return $dir.$file;
262  }
263}
264
265?>
Note: See TracBrowser for help on using the repository browser.