source: extensions/AdditionalPages/additional_page.php @ 9345

Last change on this file since 9345 was 9345, checked in by patdenice, 10 years ago

Use ENGINE=MyISAM for table creation.
Compatibility with AMM.
Compatibility with $confrandom_index_redirect parameter.

File size: 3.7 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5function check_random_index_redirect()
6{
7  global $conf;
8
9  if (!empty($conf['ap_random_index_redirect']))
10  {
11    $random_index_redirect = array();
12    foreach ($conf['ap_random_index_redirect'] as $random_url => $random_url_condition)
13    {
14      if (empty($random_url_condition) or eval($random_url_condition))
15      {
16        $random_index_redirect[] = $random_url;
17      }
18    }
19    if (!empty($random_index_redirect))
20    {
21      redirect($random_index_redirect[mt_rand(0, count($random_index_redirect)-1)]);
22    }
23  }
24  return true;
25}
26
27global $template, $user;
28
29$identifier = $page['ap_homepage'] ? $conf['AP']['homepage'] : $tokens[1];
30
31if (function_exists('get_extended_desc'))
32  add_event_handler('AP_render_content', 'get_extended_desc');
33
34// Retrieve page data
35$query = 'SELECT id, title , content, users, groups, level, permalink, standalone
36FROM ' . ADD_PAGES_TABLE . '
37';
38$query .= is_numeric($identifier) ?
39  'WHERE id = '.$identifier.';' :
40  'WHERE permalink = "'.$identifier.'";';
41
42$row = pwg_db_fetch_assoc(pwg_query($query));
43
44// Page not found
45if (empty($row))
46{
47  if ($page['ap_homepage']) return;
48  page_not_found('Requested page does not exist');
49}
50
51// Redirect with permalink if exist
52if (is_numeric($identifier) and !empty($row['permalink']) and !$page['ap_homepage'])
53{
54  redirect(make_index_url().'/page/' . $row['permalink']);
55}
56
57// Access controls
58if (!is_admin() or (!is_admin() xor $page['ap_homepage']))
59{
60  // authorized level
61  if ($user['level'] < $row['level'])
62  {
63    if ($page['ap_homepage'] and check_random_index_redirect()) return;
64    page_forbidden(l10n('You are not authorized to access the requested page'));
65  }
66
67  // authorized users
68  if (isset($row['users']))
69  {
70    $authorized_users = explode(',', $row['users']);
71    if (!in_array($user['status'], $authorized_users))
72    {
73      if ($page['ap_homepage'] and check_random_index_redirect()) return;
74      page_forbidden(l10n('You are not authorized to access the requested page'));
75    }
76  }
77
78  // authorized groups
79  if (!empty($row['groups']))
80  {
81    $query = 'SELECT group_id
82FROM ' . USER_GROUP_TABLE . '
83WHERE user_id = ' . $user['id'] . '
84  AND group_id IN (' . $row['groups'] . ')
85;';
86    $groups = array_from_query($query, 'group_id');
87    if (empty($groups))
88    {
89      if ($page['ap_homepage'] and check_random_index_redirect()) return;
90      page_forbidden(l10n('You are not authorized to access the requested page'));
91    }
92  }
93}
94
95// Display standalone page
96if ($row['standalone'] == 'true')
97{
98  echo $row['content'];
99  exit;
100}
101
102// Page initilization
103$page['section'] = 'additional_page';
104
105$page['additional_page'] = array(
106  'id' => $row['id'],
107  'permalink' => @$row['permalink'],
108  'title' => trigger_event('AP_render_content', $row['title']),
109  'content' => trigger_event('AP_render_content', $row['content']),
110);
111
112add_event_handler('loc_end_index', 'ap_set_index');
113
114function ap_set_index()
115{
116  global $template, $page, $conf;
117
118  $template->assign(array(
119    'TITLE' => $page['additional_page']['title'],
120    'PLUGIN_INDEX_CONTENT_BEGIN' => $page['additional_page']['content'],
121    )
122  );
123
124  if ($conf['AP']['show_home'] and !$page['ap_homepage'])
125  {
126    $template->assign('PLUGIN_INDEX_ACTIONS' , '
127      <li><a href="'.make_index_url().'" title="' . l10n('return to homepage') . '">
128        <img src="' . $template->get_themeconf('icon_dir') . '/home.png" class="button" alt="' . l10n('home') . '"/></a>
129      </li>');
130  }
131  if (is_admin())
132  {
133    $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');
134  }
135  $template->clear_assign(array('U_MODE_POSTED', 'U_MODE_CREATED'));
136}
137
138?>
Note: See TracBrowser for help on using the repository browser.