source: extensions/PWG_Stuffs/class.inc.php @ 9692

Last change on this file since 9692 was 9490, checked in by patdenice, 13 years ago

Remove piclens module.
Update localisations.

File size: 6.5 KB
RevLine 
[3609]1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5class 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]54SELECT DISTINCT id, name, path, datas, groups, show_title, id_line, width
[3609]55FROM ' . STUFFS_TABLE . '
[9383]56LEFT JOIN ' . USER_GROUP_TABLE . '
57  ON user_id = '.$user['id'].'
58WHERE (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"
62ORDER 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';
[9449]83        $show = unserialize($module['datas']);
84        if (!$show)
[7541]85        {
86          add_event_handler('loc_end_index', 'hide_main_block');
87        }
[9369]88        continue;
89      }
[9410]90
91      preg_match('#^'.preg_quote(PHPWG_PLUGINS_PATH).'([^/]*?)/#', $module['path'], $match);
92      if (!isset($pwg_loaded_plugins[$match[1]]))
[7855]93      {
[9369]94        continue;
95      }
[7541]96
[9369]97      $datas = (!empty($module['datas']) ? unserialize($module['datas']) : false);
[3609]98      $block = array();
99
[9490]100      @include($module['path'].'main.inc.php');
[3609]101
[9369]102      if (!empty($block['TEMPLATE']))
[3609]103      {
[9369]104        $block['ID'] = $module['id'];
105        if ($module['show_title'] == 'true')
106        {
107          $block['TITLE'] = trigger_event('render_stuffs_name', $module['name']);
108        }
109        if (is_admin())
110        {
111          $block['U_EDIT'] = PHPWG_ROOT_PATH.'admin.php?page=plugin&amp;section='.STUFFS_DIR.'%2Fadmin%2Fadmin.php&amp;tab=edit_module&amp;edit='.$module['id'].'&amp;redirect='.urlencode(urlencode($_SERVER['REQUEST_URI']));
112        }
113        $this->set_tpl_block($block, $module);
[3609]114      }
115    }
116  }
117  /* Set template blocks  */
[9369]118  function set_tpl_block($block, $module)
119  {
120    if (!empty($module['id_line']))
[3609]121    {
122      $block['id_line'] = $module['id_line'];
123      $block['given_width'] = !empty($module['width']) ? $module['width'] : '';
124
125      if (!empty($this->blocks[$this->pos]))
126      {
127        $last = end($this->blocks[$this->pos]);
128        $key = key($this->blocks[$this->pos]);
129        $penul = prev($this->blocks[$this->pos]);
130
131        if (isset($last['id_line']) and $last['id_line'] == $module['id_line'])
132        {
133          if (isset($penul['id_line']) and $penul['id_line'] == $module['id_line'])
134          {
135            $i = 3;
136            !$block['given_width'] or $i--;
137            !$last['given_width'] or $i--;
138            !$penul['given_width'] or $i--;
139
140            !$i or $default_width = intval((100 - $block['given_width'] - $last['given_width'] - $penul['given_width']) / $i);
141
142            $penul['WIDTH'] = $penul['given_width'] ? $penul['given_width'] : $default_width;
143            $block['WIDTH'] = $block['given_width'] ? $block['given_width'] : $default_width;
144
145            $block['CLASS'] = 'right_block';
146            $block['new_line'] = false;
147            $block['end_line'] = false;
148            $last['end_line'] = true;
149            $this->blocks[$this->pos][$key-1] = $penul;
150            $this->blocks[$this->pos][$key] = $block;
151            $this->blocks[$this->pos][] = $last;
152            return;
153          }
154          else
155          {
156            if (empty($block['given_width']) and empty($last['given_width']))
157            {
158              $last['WIDTH'] = 50;
159            }
160            elseif ($block['given_width']>0)
161            {
162              $last['WIDTH'] = 100 - $block['given_width'];
163            }
164            else
165            {
166              $last['WIDTH'] = $last['given_width'];
167            }
168            $block['CLASS'] = 'middle_block';
169            $last['CLASS'] = 'left_block';
170            $block['new_line'] = false;
171            $block['end_line'] = true;
172            $last['end_line'] = false;
173            $this->blocks[$this->pos][$key] = $last;
174            $this->blocks[$this->pos][] = $block;
175            return;
176          }
177        }
178      }
179    }
180
181    $block['new_line'] = true;
182    $block['end_line'] = true;
183    $block['CLASS'] = 'middle_block';
[9369]184    $this->blocks[$this->pos][] = $block;
185  }
[3609]186
[5727]187  static function prefilter_index_css($source, &$smarty)
[3609]188  {
[5727]189    $css = array(
[9449]190      '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}plugins/'.STUFFS_DIR.'/theme/stuffs_index.css">'
[5727]191    );
[3609]192
[5727]193    foreach ($smarty->get_template_vars('themes') as $theme)
[3609]194    {
[7336]195      if (file_exists(PHPWG_THEMES_PATH.$theme['id'].'/stuffs_index.css'))
[5727]196      {
197        array_push($css, '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}themes/'.$theme['id'].'/stuffs_index.css">');
198      }
[3609]199    }
[5727]200
201    $source = str_replace("\n</head>", "\n".implode( "\n", $css )."\n</head>", $source);
202
203    return $source;
204  }
205
206  static function prefilter_picture_css($source, &$smarty)
207  {
208    $css = array(
[9449]209      '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}plugins/'.STUFFS_DIR.'/theme/stuffs_picture.css">'
[5727]210    );
211
212    foreach ($smarty->get_template_vars('themes') as $theme)
[3609]213    {
[5727]214      if (file_exists(PHPWG_THEMES_DIR.$theme['id'].'/stuffs_picture.css'))
215      {
216        array_push($css, '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}themes/'.$theme['id'].'/stuffs_picture.css">');
217      }
[3609]218    }
[5727]219
220    if (!empty($css))
[3609]221    {
[5727]222      $source = str_replace("\n</head>", "\n".implode( "\n", $css )."\n</head>", $source);
[3609]223    }
[5727]224
225    return $source;
[3609]226  }
227}
228
[7402]229?>
Note: See TracBrowser for help on using the repository browser.