source: extensions/AdditionalPages/additional_page.php @ 9261

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

New administration pannel for additional pages.
Better url.
Add permalinks.

File size: 2.8 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['is_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
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['is_homepage']) return;
28  page_not_found('Requested page does not exist');
29}
30
31if (is_numeric($identifier) and !empty($row['permalink']) and !$page['is_homepage'])
32{
33  redirect(make_index_url().'/page/' . $row['permalink']);
34}
35
36$page['additional_page'] = array(
37  'id' => $row['id'],
38  'permalink' => @$row['permalink'],
39  'title' => trigger_event('AP_render_content', $row['title']),
40  'content' => trigger_event('AP_render_content', $row['content']),
41);
42
43// Utilisateurs autorisés
44if (!empty($row['users']))
45{
46  $authorized_users = explode(',', $row['users']);
47  if (!is_admin() and $conf['additional_pages']['user_perm'] and !in_array($user['status'], $authorized_users))
48  {
49    if ($page['is_homepage']) return;
50        page_forbidden(l10n('You are not authorized to access the requested page'));
51  }
52}
53
54// Groupe autorisé
55if (!empty($row['groups']))
56{
57  $q = 'SELECT *
58FROM ' . USER_GROUP_TABLE . '
59WHERE user_id = ' . $user['id'] . ' AND group_id IN (' . $row['groups'] . ');';
60  $array = mysql_fetch_array(pwg_query($q));
61  if (!is_admin() and $conf['additional_pages']['group_perm'] and empty($array))
62  {
63    if ($page['is_homepage']) return;
64        page_forbidden(l10n('You are not authorized to access the requested page'));
65  }
66}
67
68add_event_handler('loc_end_index', 'ap_set_index');
69
70function ap_set_index()
71{
72  global $template, $page, $conf;
73
74  $template->assign(array(
75    'TITLE' => $page['additional_page']['title'],
76    'PLUGIN_INDEX_CONTENT_BEGIN' => $page['additional_page']['content'],
77    )
78  );
79
80  if ($conf['additional_pages']['show_home'])
81  {
82    $template->assign('PLUGIN_INDEX_ACTIONS' , '
83      <li><a href="'.make_index_url().'" title="' . l10n('return to homepage') . '">
84        <img src="' . $template->get_themeconf('icon_dir') . '/home.png" class="button" alt="' . l10n('home') . '"/></a>
85      </li>');
86  }
87  if (is_admin())
88  {
89    $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');
90  }
91  $template->clear_assign(array('U_MODE_POSTED', 'U_MODE_CREATED'));
92}
93
94?>
Note: See TracBrowser for help on using the repository browser.