source: extensions/AdditionalPages/additional_page.php @ 9302

Last change on this file since 9302 was 9272, checked in by patdenice, 13 years ago

New functionalities

File size: 3.1 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $template, $user;
6
7$page['section'] = 'additional_page';
8$identifier = $page['ap_homepage'] ? $conf['additional_pages']['homepage'] : $tokens[1];
9
10load_language('plugin.lang.php', AP_PATH);
11
12if (function_exists('get_extended_desc'))
13  add_event_handler('AP_render_content', 'get_extended_desc');
14
15// Récupération des données de la page
16$query = 'SELECT id, title , content, users, groups, permalink, standalone
17FROM ' . ADD_PAGES_TABLE . '
18';
19$query .= is_numeric($identifier) ?
20  'WHERE id = '.$identifier.';' :
21  'WHERE permalink = "'.$identifier.'";';
22
23$row = mysql_fetch_assoc(pwg_query($query));
24
25if (empty($row))
26{
27  if ($page['ap_homepage']) return;
28  page_not_found('Requested page does not exist');
29}
30
31if (is_numeric($identifier) and !empty($row['permalink']) and !$page['ap_homepage'])
32{
33  redirect(make_index_url().'/page/' . $row['permalink']);
34}
35
36if (!$page['ap_homepage'] and $row['id'] == $conf['additional_pages']['homepage'])
37{
38  redirect(make_index_url());
39}
40
41$page['additional_page'] = array(
42  'id' => $row['id'],
43  'permalink' => @$row['permalink'],
44  'title' => trigger_event('AP_render_content', $row['title']),
45  'content' => trigger_event('AP_render_content', $row['content']),
46  'standalone' => ($row['standalone'] == 'true')
47);
48
49// Utilisateurs autorisés
50if (!empty($row['users']))
51{
52  $authorized_users = explode(',', $row['users']);
53  if (!is_admin() and $conf['additional_pages']['user_perm'] and !in_array($user['status'], $authorized_users))
54  {
55    if ($page['ap_homepage']) return;
56        page_forbidden(l10n('You are not authorized to access the requested page'));
57  }
58}
59
60// Groupe autorisé
61if (!empty($row['groups']))
62{
63  $q = 'SELECT *
64FROM ' . USER_GROUP_TABLE . '
65WHERE user_id = ' . $user['id'] . ' AND group_id IN (' . $row['groups'] . ');';
66  $array = mysql_fetch_array(pwg_query($q));
67  if (!is_admin() and $conf['additional_pages']['group_perm'] and empty($array))
68  {
69    if ($page['ap_homepage']) return;
70        page_forbidden(l10n('You are not authorized to access the requested page'));
71  }
72}
73
74if ($page['additional_page']['standalone'])
75{
76  echo $page['additional_page']['content'];
77  exit;
78}
79
80add_event_handler('loc_end_index', 'ap_set_index');
81
82function ap_set_index()
83{
84  global $template, $page, $conf;
85
86  $template->assign(array(
87    'TITLE' => $page['additional_page']['title'],
88    'PLUGIN_INDEX_CONTENT_BEGIN' => $page['additional_page']['content'],
89    )
90  );
91
92  if ($conf['additional_pages']['show_home'] and !$page['ap_homepage'])
93  {
94    $template->assign('PLUGIN_INDEX_ACTIONS' , '
95      <li><a href="'.make_index_url().'" title="' . l10n('return to homepage') . '">
96        <img src="' . $template->get_themeconf('icon_dir') . '/home.png" class="button" alt="' . l10n('home') . '"/></a>
97      </li>');
98  }
99  if (is_admin())
100  {
101    $template->assign('U_EDIT', PHPWG_ROOT_PATH.'admin.php?page=plugin&amp;section='.AP_DIR.'%2Fadmin%2Fadmin.php&amp;tab=edit_page&amp;edit='.$page['additional_page']['id'].'&amp;redirect=true');
102  }
103  $template->clear_assign(array('U_MODE_POSTED', 'U_MODE_CREATED'));
104}
105
106?>
Note: See TracBrowser for help on using the repository browser.