Ignore:
Timestamp:
Feb 17, 2011, 4:27:09 PM (13 years ago)
Author:
patdenice
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AdditionalPages/additional_page.php

    r8132 r9261  
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
    5 global $template, $conf, $user;
     5global $template, $user;
     6
     7$page['section'] = 'additional_page';
     8$identifier = $page['is_homepage'] ? $conf['additional_pages']['homepage'] : $tokens[1];
    69
    710load_language('plugin.lang.php', AP_PATH);
    811
    9 $ap_id = explode('additional_page/' , $_SERVER['REQUEST_URI']);
    10 $ap_id = explode('&' , $ap_id[1]);
    11 $ap_conf = explode ("," , $conf['additional_pages']);
     12if (function_exists('get_extended_desc'))
     13  add_event_handler('AP_render_content', 'get_extended_desc');
    1214
    1315// Récupération des données de la page
    14 $q = 'SELECT title , pos , text
     16$query = 'SELECT id, title , content, users, groups, permalink
    1517FROM ' . ADD_PAGES_TABLE . '
    16 WHERE id = ' . $ap_id[0] . ';';
    17 $result = mysql_fetch_assoc(pwg_query($q));
     18';
     19$query .= is_numeric($identifier) ?
     20  'WHERE id = '.$identifier.';' :
     21  'WHERE permalink = "'.$identifier.'";';
    1822
    19 if (empty($result))
     23$row = mysql_fetch_assoc(pwg_query($query));
     24
     25if (empty($row))
    2026{
    21   page_not_found('This page does not exist', 'index.php?');
     27  if ($page['is_homepage']) return;
     28  page_not_found('Requested page does not exist');
    2229}
    2330
     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
    2443// Utilisateurs autorisés
    25 if (strpos($result['title'] , 'user_id='))
     44if (!empty($row['users']))
    2645{
    27   $array = explode('/user_id=' , $result['title']);
    28   $result['title'] = $array[0];
    29   $authorized_users = explode(',', $array[1]);
    30   if (!is_admin() and $ap_conf[7] == 'on' and !in_array($user['status'], $authorized_users))
     46  $authorized_users = explode(',', $row['users']);
     47  if (!is_admin() and $conf['additional_pages']['user_perm'] and !in_array($user['status'], $authorized_users))
    3148  {
    32         page_not_found('User not allowed', 'index.php?');
     49    if ($page['is_homepage']) return;
     50        page_forbidden(l10n('You are not authorized to access the requested page'));
    3351  }
    3452}
    3553
    3654// Groupe autorisé
    37 if (strpos($result['title'] , 'group_id='))
     55if (!empty($row['groups']))
    3856{
    39   $array = explode('/group_id=' , $result['title']);
    40   $result['title'] = $array[0];
    41   $authorized_groups = $array[1];
    42 
    4357  $q = 'SELECT *
    4458FROM ' . USER_GROUP_TABLE . '
    45 WHERE user_id = ' . $user['id'] . ' AND group_id IN (' . $authorized_groups . ');';
     59WHERE user_id = ' . $user['id'] . ' AND group_id IN (' . $row['groups'] . ');';
    4660  $array = mysql_fetch_array(pwg_query($q));
    47   if (!is_admin() and $ap_conf[6] == 'on' and empty($array))
     61  if (!is_admin() and $conf['additional_pages']['group_perm'] and empty($array))
    4862  {
    49         page_not_found('User not allowed', 'index.php?');
     63    if ($page['is_homepage']) return;
     64        page_forbidden(l10n('You are not authorized to access the requested page'));
    5065  }
    5166}
    5267
    53 // Envoi de la page
    54 // Extended description
    55 if (function_exists('get_extended_desc'))
    56   add_event_handler('AP_render_content', 'get_extended_desc');
     68add_event_handler('loc_end_index', 'ap_set_index');
    5769
    58 $template->assign(array(
    59   'TITLE' => trigger_event('AP_render_content', $result['title']),
    60   'PLUGIN_INDEX_CONTENT_BEGIN' => trigger_event('AP_render_content', $result['text'])));
    61 if (isset($ap_conf[2]) and $ap_conf[2] == 'on')
     70function ap_set_index()
    6271{
    63   $template->assign('PLUGIN_INDEX_ACTIONS' , '
    64     <li><a href="' . make_index_url() . '" title="' . l10n('return to homepage') . '">
    65       <img src="' . $template->get_themeconf('icon_dir') . '/home.png" class="button" alt="' . l10n('home') . '"/></a>
    66     </li>');
    67 }
    68 if (is_admin())
    69 {
    70   $template->assign('U_EDIT', PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . AP_DIR . '%2Fadmin%2Fadd_page.php&amp;edit=' . $ap_id[0]);
     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'));
    7192}
    7293
    73 $template->clear_assign(array('U_MODE_POSTED', 'U_MODE_CREATED'));
    74 
    7594?>
Note: See TracChangeset for help on using the changeset viewer.