source: extensions/AdditionalPages/additional_page.php @ 9310

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

Lot of optimization.
Add privacy level management.

File size: 3.3 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
10if (function_exists('get_extended_desc'))
11  add_event_handler('AP_render_content', 'get_extended_desc');
12
13// Retrieve page data
14$query = 'SELECT id, title , content, users, groups, level, permalink, standalone
15FROM ' . ADD_PAGES_TABLE . '
16';
17$query .= is_numeric($identifier) ?
18  'WHERE id = '.$identifier.';' :
19  'WHERE permalink = "'.$identifier.'";';
20
21$row = pwg_db_fetch_assoc(pwg_query($query));
22
23if (empty($row))
24{
25  if ($page['ap_homepage']) return;
26  page_not_found('Requested page does not exist');
27}
28
29if (is_numeric($identifier) and !empty($row['permalink']) and !$page['ap_homepage'])
30{
31  redirect(make_index_url().'/page/' . $row['permalink']);
32}
33
34if (!$page['ap_homepage'] and $row['id'] == $conf['additional_pages']['homepage'])
35{
36  redirect(make_index_url());
37}
38
39$page['additional_page'] = array(
40  'id' => $row['id'],
41  'permalink' => @$row['permalink'],
42  'title' => trigger_event('AP_render_content', $row['title']),
43  'content' => trigger_event('AP_render_content', $row['content']),
44  'standalone' => ($row['standalone'] == 'true')
45);
46
47if (!is_admin() and !$page['ap_homepage'])
48{
49  // authorized users
50  if (!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  // authorized groups
61  if (!empty($row['groups']))
62  {
63    $q = 'SELECT *
64  FROM ' . USER_GROUP_TABLE . '
65  WHERE 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
74  // authorized level
75  if ($user['level'] < $row['level'])
76  {
77    page_forbidden(l10n('You are not authorized to access the requested page'));
78  }
79}
80
81// Display standalone page
82if ($page['additional_page']['standalone'])
83{
84  echo $page['additional_page']['content'];
85  exit;
86}
87
88add_event_handler('loc_end_index', 'ap_set_index');
89
90function ap_set_index()
91{
92  global $template, $page, $conf;
93
94  $template->assign(array(
95    'TITLE' => $page['additional_page']['title'],
96    'PLUGIN_INDEX_CONTENT_BEGIN' => $page['additional_page']['content'],
97    )
98  );
99
100  if ($conf['additional_pages']['show_home'] and !$page['ap_homepage'])
101  {
102    $template->assign('PLUGIN_INDEX_ACTIONS' , '
103      <li><a href="'.make_index_url().'" title="' . l10n('return to homepage') . '">
104        <img src="' . $template->get_themeconf('icon_dir') . '/home.png" class="button" alt="' . l10n('home') . '"/></a>
105      </li>');
106  }
107  if (is_admin())
108  {
109    $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');
110  }
111  $template->clear_assign(array('U_MODE_POSTED', 'U_MODE_CREATED'));
112}
113
114?>
Note: See TracBrowser for help on using the repository browser.