source: extensions/PWG_Stuffs/functions.inc.php @ 9691

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

Remove piclens module.
Update localisations.

File size: 4.1 KB
Line 
1<?php
2
3add_event_handler('render_stuffs_name', 'get_user_language_desc');
4
5if (!function_exists('get_user_language_desc'))
6{
7  function get_user_language_desc($desc)
8  {
9    global $user;
10   
11    $user_lang = substr($user['language'], 0, 2);
12
13    if (!substr_count(strtolower($desc), '[lang=' . $user_lang . ']'))
14    {
15      $user_lang = 'default';
16    }
17   
18    if (substr_count(strtolower($desc), '[lang=' . $user_lang . ']'))
19    {
20      // la balise avec la langue de l'utilisateur a été trouvée
21      $patterns[] = '#(^|\[/lang\])(.*?)(\[lang=(' . $user_lang . '|all)\]|$)#is';
22      $replacements[] = '';
23      $patterns[] = '#\[lang=(' . $user_lang . '|all)\](.*?)\[/lang\]#is';
24      $replacements[] = '\\1';
25    }
26    else
27    {
28      // la balise avec la langue de l'utilisateur n'a pas été trouvée
29      // On prend tout ce qui est hors balise
30      $patterns[] = '#\[lang=all\](.*?)\[/lang\]#is';
31      $replacements[] = '\\1';
32      $patterns[] = '#\[lang=.*\].*\[/lang\]#is';
33      $replacements[] = '';
34    }
35    return preg_replace($patterns, $replacements, $desc);
36  }
37}
38
39function get_default_stuffs_modules($modules)
40{
41  $dir = opendir(STUFFS_PATH . 'modules/');
42  while ($file = readdir($dir))
43  {
44    if ($file != '.' and $file != '..' and $file != '.svn' and $file != 'piclenswall')
45    {
46      $path = STUFFS_PATH . 'modules/' . $file;
47      if (is_dir($path) and !is_link($path))
48      {
49        array_push($modules, array(
50          'path' => $path,
51          'name' => l10n('module_name_' . strtolower($file)),
52          'description' => l10n('module_desc_' . strtolower($file)),
53          )
54        );
55      }
56    }
57  }
58  closedir($dir);
59  return $modules;
60}
61
62function pwgs_picture_special_sections()
63{
64  global $page, $conf;
65
66  if (preg_match('#&(pwgs_..)=#', $_SERVER['REQUEST_URI'], $matches))
67  {
68    if (isset($_GET['action']))
69    {
70      if (isset($page['category']))
71      {
72        $page['section'] = 'category/'.$page['category']['id'];
73        unset($page['category']);
74      }
75      $page['section'] .= $matches[0] . $_GET[$matches[1]];
76    }
77    else
78    {
79      unset($page['flat']);
80      $page['PWG_Stuffs_section'] = $matches[1];
81      $page['items'] = explode(',', $_GET[$matches[1]]);
82      $page['rank_of'] = array_flip($page['items']);
83      switch ($matches[1])
84      {
85        case 'pwgs_mv': $title = l10n('Most visited'); break;
86        case 'pwgs_br': $title = l10n('Best rated'); break;
87        case 'pwgs_re': $title = l10n('Recent pictures'); break;
88        case 'pwgs_ra': $title = l10n('Random pictures'); break;
89      }
90      $page['title'] .= $conf['level_separator'] . $title;
91      add_event_handler('loc_end_page_header', 'add_pwgs_url_params');
92    }
93  }
94}
95
96function add_pwgs_url_params()
97{
98  global $page, $template;
99
100  $param = $page['PWG_Stuffs_section'];
101
102  $urls = array(
103    'first.U_IMG',
104    'previous.U_IMG',
105    'next.U_IMG',
106    'last.U_IMG',
107    'slideshow.U_START_PLAY',
108    'slideshow.U_STOP_PLAY',
109    'slideshow.U_START_REPEAT',
110    'slideshow.U_STOP_REPEAT',
111    'slideshow.U_DEC_PERIOD',
112    'slideshow.U_INC_PERIOD',
113    'U_SLIDESHOW_START',
114    'U_SLIDESHOW_STOP',
115    'U_METADATA',
116    'favorite.U_FAVORITE',
117    'U_SET_AS_REPRESENTATIVE',
118    'U_CADDIE',
119    'rating.F_ACTION',
120    'comment_add.F_ACTION',
121    'page_refresh.U_REFRESH',
122  );
123
124  foreach ($urls as $url)
125  {
126    $k = explode('.', $url);
127    if (isset($k[1]) and isset($template->smarty->_tpl_vars[$k[0]][$k[1]]))
128    {
129      $template->smarty->_tpl_vars[$k[0]][$k[1]] = add_url_params($template->smarty->_tpl_vars[$k[0]][$k[1]], array($param => $_GET[$param]));
130    }
131    elseif (!isset($k[1]) and isset($template->smarty->_tpl_vars[$k[0]]))
132    {
133      $template->smarty->_tpl_vars[$k[0]] = add_url_params($template->smarty->_tpl_vars[$k[0]], array($param => $_GET[$param]));
134    }
135  }
136}
137
138function hide_main_block()
139{
140  global $page, $template;
141
142  if ($page['stuffs_section'] == 'on_home')
143  {
144    $template->set_prefilter('index', 'hide_main_block_prefilter');
145  }
146}
147
148function hide_main_block_prefilter($content, $smarty)
149{
150  return preg_replace('#<div id="content" class="content">.*</div> <!-- content -->#s', '', $content);
151}
152
153?>
Note: See TracBrowser for help on using the repository browser.