source: extensions/AdditionalPages/trunk/main.inc.php @ 9659

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

Create branch and trunk directories.

File size: 3.6 KB
RevLine 
[3609]1<?php
2/*
3Plugin Name: Additional Pages
[3825]4Version: auto
[3609]5Description: Add additional pages in menubar.
[9261]6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=153
[3609]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
[9323]19$conf['AP'] = @unserialize($conf['additional_pages']);
[9261]20
[9312]21// Need upgrade?
[9350]22if (!isset($conf['AP']['language_perm']))
[9310]23  include(AP_PATH.'admin/upgrade.inc.php');
[9262]24
[9345]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
[9312]32// Admin menu
[3609]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
[9312]41// Section init
[3609]42function section_init_additional_page()
43{
[9261]44  global $tokens, $conf, $page;
[3609]45
[9350]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
[9272]52  $page['ap_homepage'] = (count($tokens) == 1 and empty($tokens[0]));
[3609]53
[9323]54  if (($tokens[0] == 'page' and !empty($tokens[1])) or ($page['ap_homepage'] and !is_null($conf['AP']['homepage'])))
[9261]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]);
[3609]59}
60
[9312]61// Menubar
[9310]62function register_ap_menubar_blocks($menu_ref_arr)
63{
[9351]64  global $conf, $user;
65
[9310]66  $menu = & $menu_ref_arr[0];
67  if ($menu->get_id() != 'menubar') return;
[9351]68
69  $conf['AP']['block_title'] = isset($conf['AP']['languages'][$user['language']]) ?
70    $conf['AP']['languages'][$user['language']] : @$conf['AP']['languages']['default'];
71
72  if (empty($conf['AP']['block_title']))
73    $conf['AP']['block_title'] = 'Additional Pages';
74
75  $menu->register_block( new RegisteredBlock( 'mbAdditionalPages', $conf['AP']['block_title'], 'Additional Pages'));
[9310]76}
[9261]77
[9310]78function ap_apply($menu_ref_arr)
79{
80  global $template, $conf, $user;
81
82  $menu = & $menu_ref_arr[0];
83 
84  if ( ($block = $menu->get_block( 'mbAdditionalPages' ) ) != null )
85  {
[9312]86    $query = 'SELECT DISTINCT id, title, permalink
[9310]87FROM ' . ADD_PAGES_TABLE . '
88LEFT JOIN ' . USER_GROUP_TABLE . '
89  ON user_id = '.$user['id'].'
[9312]90WHERE (lang IS NULL OR lang = "'.$user['language'].'")
[9310]91  AND (users IS NULL OR users LIKE "%'.$user['status'].'%")
92  AND (groups IS NULL OR groups REGEXP CONCAT("(^|,)",group_id,"(,|$)"))
93  AND level <= '.$user['level'].'
94  AND pos >= 0
95ORDER BY pos ASC
96;';
97    $result = pwg_query($query);
98    $data = array();
99    while ($row = pwg_db_fetch_assoc($result))
100    {
101      $url = make_index_url().'/page/'.(isset($row['permalink']) ? $row['permalink'] : $row['id']);
[9350]102      array_push($data, array('URL' => $url, 'LABEL' => trigger_event('AP_render_title', $row['title'])));
[9310]103    }
104
105    if (!empty($data))
106    {
107      $template->set_template_dir(AP_PATH.'template/');
[9351]108      $block->set_title($conf['AP']['block_title']);
[9310]109      $block->template = 'menubar_additional_pages.tpl';
110      $block->data = $data;
111    }
112  }
113}
114
[3609]115add_event_handler('get_admin_plugin_menu_links', 'additional_pages_admin_menu');
116add_event_handler('loc_end_section_init', 'section_init_additional_page');
[9310]117add_event_handler('blockmanager_register_blocks', 'register_ap_menubar_blocks');
118add_event_handler('blockmanager_apply', 'ap_apply');
[3609]119
[3292]120?>
Note: See TracBrowser for help on using the repository browser.