source: extensions/AdditionalPages/main.inc.php @ 9350

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

Extended description now work on page title.
Language restriction is now optionnal.

File size: 3.5 KB
Line 
1<?php
2/*
3Plugin Name: Additional Pages
4Version: auto
5Description: Add additional pages in menubar.
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=153
7Author: P@t
8Author URI: http://www.gauchon.com
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13global $prefixeTable, $conf;
14
15define('AP_DIR' , basename(dirname(__FILE__)));
16define('AP_PATH' , PHPWG_PLUGINS_PATH . AP_DIR . '/');
17define('ADD_PAGES_TABLE' , $prefixeTable . 'additionalpages');
18
19$conf['AP'] = @unserialize($conf['additional_pages']);
20
21// Need upgrade?
22if (!isset($conf['AP']['language_perm']))
23  include(AP_PATH.'admin/upgrade.inc.php');
24
25// Unset $conf['random_index_redirect'] if homepage is defined
26if (!empty($conf['random_index_redirect']) and !is_null($conf['AP']['homepage']))
27{
28  $conf['ap_random_index_redirect'] = $conf['random_index_redirect'];
29  $conf['random_index_redirect'] = array();
30}
31
32// Admin menu
33function additional_pages_admin_menu($menu)
34{
35    array_push($menu, array(
36      'NAME' => 'Additional Pages',
37      'URL' => get_admin_plugin_menu_link(AP_PATH . 'admin/admin.php')));
38    return $menu;
39}
40
41// Section init
42function section_init_additional_page()
43{
44  global $tokens, $conf, $page;
45
46  if (defined('EXTENDED_DESC_PATH'))
47  {
48    add_event_handler('AP_render_content', 'get_extended_desc');
49    add_event_handler('AP_render_title', 'get_user_language_desc');
50  }
51
52  $page['ap_homepage'] = (count($tokens) == 1 and empty($tokens[0]));
53
54  if (($tokens[0] == 'page' and !empty($tokens[1])) or ($page['ap_homepage'] and !is_null($conf['AP']['homepage'])))
55    include(AP_PATH . 'additional_page.php');
56
57  if ($tokens[0] == 'additional_page' and !empty($tokens[1]))
58    redirect(make_index_url().'/page/'.$tokens[1]);
59}
60
61// Menubar
62function register_ap_menubar_blocks($menu_ref_arr)
63{
64  $menu = & $menu_ref_arr[0];
65  if ($menu->get_id() != 'menubar') return;
66  $menu->register_block( new RegisteredBlock( 'mbAdditionalPages', 'Additional Pages', 'P@t'));
67}
68
69function ap_apply($menu_ref_arr)
70{
71  global $template, $conf, $user;
72
73  $menu = & $menu_ref_arr[0];
74 
75  if ( ($block = $menu->get_block( 'mbAdditionalPages' ) ) != null )
76  {
77    $query = 'SELECT DISTINCT id, title, permalink
78FROM ' . ADD_PAGES_TABLE . '
79LEFT JOIN ' . USER_GROUP_TABLE . '
80  ON user_id = '.$user['id'].'
81WHERE (lang IS NULL OR lang = "'.$user['language'].'")
82  AND (users IS NULL OR users LIKE "%'.$user['status'].'%")
83  AND (groups IS NULL OR groups REGEXP CONCAT("(^|,)",group_id,"(,|$)"))
84  AND level <= '.$user['level'].'
85  AND pos >= 0
86ORDER BY pos ASC
87;';
88    $result = pwg_query($query);
89    $data = array();
90    while ($row = pwg_db_fetch_assoc($result))
91    {
92      $url = make_index_url().'/page/'.(isset($row['permalink']) ? $row['permalink'] : $row['id']);
93      array_push($data, array('URL' => $url, 'LABEL' => trigger_event('AP_render_title', $row['title'])));
94    }
95
96    if (!empty($data))
97    {
98      $title = isset($conf['AP']['languages'][$user['language']]) ?
99        $conf['AP']['languages'][$user['language']] :
100        @$conf['AP']['languages']['default'];
101
102      $template->set_template_dir(AP_PATH.'template/');
103      $block->set_title($title);
104      $block->template = 'menubar_additional_pages.tpl';
105      $block->data = $data;
106    }
107  }
108}
109
110add_event_handler('get_admin_plugin_menu_links', 'additional_pages_admin_menu');
111add_event_handler('loc_end_section_init', 'section_init_additional_page');
112add_event_handler('blockmanager_register_blocks', 'register_ap_menubar_blocks');
113add_event_handler('blockmanager_apply', 'ap_apply');
114
115?>
Note: See TracBrowser for help on using the repository browser.